为什么要创建索引呢?因为索引对提高数据库的性能很有帮助,换句话说就是可以更快地找到你想要的东东(和书的目录差不多)。
   索引分为聚集索引和非聚集索引,建聚集索引时要看这个表是否已经有聚集索引了,因为一个表只能有一个。
聚集索引:
create unique clustered index first on product(id)
非聚集索引:
create index second on product(pro_name)
创建有关值在列中分布情况的统计信息:
create statistics kaka on product(id,poductname) with sample 5 percent
对所有列进行统计并禁用自动重新计算:
create statistics kaka2 on product(id,poductname) with fullscan,norecompute(*注:fullscan 与sample 100 percent一个道理)
若要还原自动重新计算:
update statistics product kaka2(作用等同于: exec sp_updatestats)
使用填充因子值80重建product表上的first聚集索引:
DBCC dbreindex('product',first,80)
重建product表上的所有索引:
DBCC dbreindex(product,'',70)
所谓填充因子是1~100之间的某个值,指定索引页保留为空的百分比,值为100时表示页将填满,所留出的存储空间量最小,在不改数据表时用此值合适,如需要改动越多值就越小越好,但查询效率降低。
指定一个填充因子:
create nonclustered index id_ind on product(id) with fillfactor=100
重命名表:
exec sp_rename 'customers','custs'
--将customers表重命名为custs
同理,重命名列:
exec sp_rename 'customers.[contact title]','title','column'