SQL2008CTP之compression

SQL2008中一個新的功能就是壓縮數據(compressed data),同樣這個玩意兒要減小最大單行數據長度,估計也就是做個標記,需要有空間.

只要數據在同一個"heap"中或者是完整的表/索引或者是索引視圖,就可以使用該功能,只不過這項功能只是在企業版或者是開發版中提供,由於沒有具體的試驗,一個非常有疑問已經產生了,使用該項功能後是不是該死的數據庫文件就不會有那麼大了?使用壓縮會不會影響性能(如果不影響爲什麼不壓縮呢?或者從根本上就應該設計壓縮的數據,不足=賺錢,"正如MS進軍防病毒軟件市場一樣",他做的數據庫佔用很大的空間,出個僅支持企業版的壓縮功能,就能賺錢)?

需要注意的就是表和索引的問題,壓縮後數據存儲順序或者會發生變化,索引的填充因子也不同,因此需要重建索引.

下面就貼幾個代碼,看看如何維護數據壓縮:

create table T1
(c1 int,
 c2 nvarchar(50)
 )
 with (data_compression=ROW)   --壓縮就分爲row和page方式,此處指定爲row
 go
 create table T2
 (c1 int,
 c2 nvarchar(50)
 )
 with (data_compression=PAGE)
 go
 create partition function myRangePF1(int)
 as range left for values(1,100,1000);
 go
 create partition scheme myRangePS1
 as partition myRangePF1
 to(test1fg,test2fg,test3fg,test4fg);
 go
 create table partitionTable1
 (col1 int,
  col2 varchar(max)
  )
  on myRangePS1(col1)
  with
  (
  data_compression=ROW on partitions(1),     --分區表同樣可以一併指定或者分開指定,修改時也可使用此語法
  data_compression=PAGE on partitions(2 to 4)
  );
  go
  create table partitionTable2
  (col1 int,
  col2 varchar(max)
  )
  on myRangePS1(col1)
  with
  (
  data_compression=Row on partitions(1,3),
  data_compression=PAGE on partitions(2,4)
  );
  go
alter table T1
rebuild with (data_compression=PAGE);
go
alter table partitionTable1 rebuild partition=1 with (data_compression=NONE);
go
create nonclustered index ix_index_1
    on t1(c2)
  with (data_compression=ROW);
  go
 
alter index ix_index_1
on t1
rebuild with (data_compression=PAGE);
go
create clustered index ix_parttab2col1
on partitionTable1(col1)
with (data_compression=ROW);
go

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章