*索引
1.分类
唯一索引
主键索引
聚集索引
非聚集索引
符合索引
全文索引
2.创建索引
CREATE [UNIQUE]/[CLUSTERED]/[UNCLUSTERED] INDEX index_name
ON table_name(column_name1,column_name2...) 这里可以有多个column
WITH FILLFACTOR=x fillfactor表示填充因子,指定一个0-100的值,指示索引页填满的控件所占的百分比
例如:
use Student
go
if exists(select * from sysindexes where name='ix_i')
drop index StudentInfo.ix_i
create nonclustered index ix_i
on StudentInfo(StudentName)
with fillfactor=30
go
3.查看索引
exec sp_helpIndex StudentInfo
查看所有的索引的参数信息
use Student
select * from sys.indexes
4.下面的表总结了何时使用聚集索引或非聚集索引(很重要):
动作描述 使用聚集索引 使用非聚集索引
列经常被分组排序 应 应
返回某范围内的数据 应 不应
一个或极少不同值 不应 不应
小数目的不同值 应 不应
大数目的不同值 不应 应
频繁更新的列 不应 应
外键列 应 应
主键列 应 应
频繁修改索引列 不应 应