SQL Server 中幾種索引的簡單理解


主鍵(Primary Key):主鍵在一個表中可以有多個,但是主鍵的內容不能為空。

create table 表名 (    字段名1 int not null,    …………,
   [constraint 約束名] primary key (字段名1, …)
 )

alter table 表名 [add constraint 約束名] primary key(字段名1 ,… )

ALTER TABLE 表名DROP CONSTRAINT 約束名

 

聚焦索引:表的物理存儲順序與指針(即邏輯)順序相同,一張表存在的聚焦索引不能超過1個。形如:按字典的字母排序查找生字;

create clustered index index_name on table_name(column asc,)

create unique clustered index index_name on table_name(column asc,) //唯一聚集索引

drop  index index_name on table_name with (online=off)

 

非聚集索引:物理與邏輯順序不同,一張表可以存在多個非聚集索引。形如:字典按部首查找生字。

 

create nonclustered index index_name on table_name(column asc,)


drop  index index_name on table_name with (online=off)

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM