为表添加普通索引的SQL语句是怎样的

如题所述

为给定表或视图创建索引。
只有表或视图的所有者才能为表创建索引。表或视图的所有者可以随时创建索引,无论表中是否有数据。可以通过指定限定的数据库名称,为另一个数据库中的表或视图创建索引。语法
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
[ WITH < index_option > [ ,...n] ]
[ ON filegroup ]< index_option > ::=
{ PAD_INDEX |
FILLFACTOR = fillfactor |
IGNORE_DUP_KEY |
DROP_EXISTING |
STATISTICS_NORECOMPUTE |
SORT_IN_TEMPDB
} 此文转自:
http://www.cnblogs.com/abcdwxc/archive/2007/12/11/990274.html
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-07-30
if object_id('索引名称') is not null /*--检查数据库是否存在索引 Drop index 表. 索引名称gocreate index 自定索引名称 on 表(列)/*这个默认赛事非聚集索引 要指定索引类型的话就在index前面写*/with fillfactor = 20go
第2个回答  2013-07-30
楼上的说的正确:那我就给你个例子把---use students --<指定库名>go/*--检查数据库是否存在索引(索引放在系统表中sysindexes中)--*/if exists(select name from sysindexes where name ='IX_stu_writtenexam') --<表名 --字段>drop index stu .IX_stu_writtenexam --如果存在删除索引gocreate nonclustered index ix_stu_writtenexam --创建非聚居索引 on stu(wriittenexam) with fillfactor =20 --填充因子go
第3个回答  2012-03-01
create Index index_name on table_name(col1_name,col2_name...);

注:
1.index_name :你建立的索引名
2.table_name:你将要加索引的表名
3.col1_name:你要加索引的列名,从col1_name往后的列名都可以为空,如果不为空就变为组合索引。
相似回答