使用SQL Server Management Studio工具登录后,选择需要创建索引的库名,然后点击工具栏上的“新建查询”,输入创建索引的SQL语句。
-- 创建聚集索引
create clustered --表示创建聚集索引
index 索引名称 --索引名称
on 表名称(字段名称)
-- 创建唯一非聚集索引
create unique nonclustered --表示创建唯一非聚集索引(字段值唯一)
index 索引名称 --索引名称
on 表名称(字段名称)
-- 创建非聚集索引
create nonclustered --表示创建唯一非聚集索引
index 索引名称 --索引名称
on 表名称(字段名称)
-- 创建非聚集复合索引
create nonclustered --表示创建唯一非聚集索引
index 索引名称 --索引名称
on 表名称(字段名称A,字段名称B)