重建索引能释放掉字段因更改而产生额外列偏移量
?
1建表和索引
create table index_test (id int identity(1,1),name sysname);
create? clustered index nonidex_id on index_test(id);
2? 插入測試數(shù)據(jù)
declare @count int=1;
while @count<=100000
begin
insert into index_test(name)
select replace(left(cast(NEWID() as varchar(50)),10) +? right(cast(NEWID() as varchar(50)),10),'-','')
set @count=@count+1
end
?
3 觀察更改前的表空間大小 data是 5920 KB
go
sp_spaceused index_test
name?rows?reserved?data?index_size?unused
index_test?100000???? ?5920 KB?5648 KB?48 KB?224 KB
4 更改列屬性
alter table index_test
alter column name varchar(50);
5 觀察更改后 表空間大小 data 是 11480 KB 說明列偏移量并不是在原來基礎(chǔ)上面增加減少的。而是從最后面開始增加。
sp_spaceused index_test
name?rows?reserved?data?index_size?unused
index_test?100000???? ?11480 KB?11280 KB?64 KB?136 KB
6 重建索引
alter index? nonidex_id on index_test rebuild with(online=on);
7 重建索引后表空間大小 data 為 3800KB
sp_spaceused index_test
name?rows?reserved?data?index_size?unused
index_test?100000???? ?3800 KB?3760 KB?16 KB?24 KB
8 線上庫嚴禁頻繁的字段屬性更改
轉(zhuǎn)載于:https://www.cnblogs.com/xwj1985/archive/2010/08/04/1792638.html
總結(jié)
以上是生活随笔為你收集整理的重建索引能释放掉字段因更改而产生额外列偏移量的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VSS源代码管理应该怎么样对bin目录及
- 下一篇: 蒙娜丽莎,品牌创新的探索者