1.什么事索引:
数据库中的索引是某个表中一列或者多列值的集合和相应的指向表中物理标志的数据页的逻辑指针清单
2.分类:
唯一索引(unique):不允许两行具有相同的索引值(创建了唯一的约束,系统将自动创建唯一索引)
主键索引(): 主键索引要求表中每个值是唯一的
聚集索引:表中各行物理顺序与键值的逻辑(索引)顺序不匹配
3.创建索引的标准:用于频繁的搜索列,用于对数据的排序的列
语法: create 【索引类型】index 索引名称 on 表名(列名) where fillfactor=填充因子值0-100 go
/********************实例*************************/
use 库名
go
if exits (select * from sysindexes where name='ix_text_name') -----检测是否存在ix_text_name 索引
drop index text.ix_text_name ----如果存在就删除
----创建索引
create nonclustered index ix_text_name ---创建一个非聚集索引
on test (name) ---为test表的name字段创建索引
with fillfactor=30 ---------- 填充因子为30%
go
select * from test(index=ix_text_name) where name='a'------ 指按照ix_text_name来进行查询