SQL2008CTP之compression

来源:互联网 发布:c语言中单引号 编辑:程序博客网 时间:2024/05/22 09:25

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