电脑软硬件应用网
当前位置: 电脑软硬件应用网 > 设计学院 > 网络编程 > 数据库 > 正文
SQL重建索引重新释放掉字段因更改而产生额外列偏移量的代码
SQL重建索引重新释放掉字段因更改而产生额外列偏移量的代码
2010-8-7 22:20:44  文/佚名   出处:网络   
本文和大家讲下如何使用SQL重建索引重新释放掉字段因更改而产生额外列偏移量的代码
1建表和索引
create table index_test (id int identity(1,1),name sysname);
create  clustered index nonidex_id on index_test(id);
2  插入测试数据
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 说明列偏移量并不是在原来基础上面增加减少的。而是从最后面开始增加。
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 线上库严禁频繁的字段属性更改
  • 上一篇文章:

  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    详解如何查找SQL数据库自增ID值不连…
    SQL教程:SQL Server备份和灾难恢复
    SQL注入攻击:防御和检查SQL注入的手…
    SQL Server日志文件丢失 进行恢复方…
    解决安装SQL Server出现command lin…
    Windows 7下如何安装SQL Server 200…
    详解SQL数据仓库之时间维度创建的开…
    解答SQL不许在视图定义ORDER BY子句…
    解答SQL不许在视图定义ORDER BY子句…
    SQL语句查询SQL2005所有表的索引碎片…
    关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 |

    Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号