重建索引能释放掉字段因更改而产生额外列偏移量
2010-08-04 22:40
302 查看
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 线上库严禁频繁的字段属性更改
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 线上库严禁频繁的字段属性更改
相关文章推荐
- MSSQL大量数据时,建立索引或添加字段后保存更改----超时------该这么办
- MSSQL大量数据时,建立索引或添加字段后保存更改----超时------该这么办
- 重建索引来释放索引所占的表空间
- 使用NaviCat无法更改MySQL数据库某个字段的名字时..先把外键和索引删除了..
- elasticsearch更改mapping(不停服务重建索引)
- LOB字段相关概念(自动创建LOB索引段和重建索引方法)
- MSSQL 大量数据时,建立索引或添加字段后保存更改提示超时的解决方法
- elasticsearch更改mapping,不停服务重建索引(转)
- ELK学习总结(4-1)elasticsearch更改mapping(不停服务重建索引)
- MSSQL SERVER 大量数据时,建立索引或添加字段后保存更改提示超时的解决方法
- 一次性重建所有聚集索引,方便释放空间
- 怎么对ArcGIS for Server发布服务的要素类进行操作(字段增删、索引重建等)
- elasticsearch更改mapping(不停服务重建索引)
- MSSQL大量数据时,建立索引或添加字段后保存更改----超时------该这么办
- Oracle重建索引
- ebs form 控制某个字段不可更改
- Oracle表与索引的分析及索引重建
- oracle分析索引,重建--分析表
- 常用脚本--在线重建或重整实例下所有索引