日期:2014-05-18  浏览次数:20493 次

SQL如何创建索引
能详细说一下SQL创建索引的语法吗?

------解决方案--------------------
SQL code
CREATE INDEX
为给定表或视图创建索引。

只有表或视图的所有者才能为表创建索引。表或视图的所有者可以随时创建索引,无论表中是否有数据。可以通过指定限定的数据库名称,为另一个数据库中的表或视图创建索引。

语法
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  
}

参

------解决方案--------------------
有点儿长,所以请查看联机丛书
create index
------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/ms188783.aspx
参考这个吧!
------解决方案--------------------
太多 自己看MSDN
------解决方案--------------------
SQL code
--非聚集:create index 索引名 on 表名(字段名) --也可以是字段名列表(复合索引)
--聚集:create clustered index 索引名 on 表名(字段名)
--唯一:create unique index 索引名 on 表名(字段名)--也可以是字段名列表(复合索引)
...

------解决方案--------------------
-----创建索引

create clustered index riqi_person on person(date)
------在person表的date字段上面创建名为riqi_person的【聚集索引】

create nonclustered index riqi_person on person(date)
------在person表的date字段上面创建名为riqi_person的【非聚集索引】

create clustered index date_person on person(date,id)
------在person表的date,age字段上面创建名为riqi_person的【复合聚集索引】

create nonclustered index date_person on person(date,age)
------在person表的date,age字段上面创建名为riqi_person的【复合非聚集索引】



-----查看索引
sp_helpindex person
------查看person表中的聚集索引和非聚集索引

【界面操作】某个数据库>>某张表>>索引


----删除索引
drop index person.p_age
------删除person表中的名为p_age的索引

------解决方案--------------------
给你一个学生版的 怎样创建索引 T-sql代码创建索引
create unique/clustered/nonclustered index Ix_索引名
on 表名(列名) with fillfactor=填充因子