Use test Go If object_id('Users') Is Not Null Drop Table Users Go Create Table Users ( ID int Identity(1,1), Code nvarchar(50), Name nvarchar(50), Constraint PK_Users_ID Primary Key(ID Asc)--默认会建立1个名称为 PK_Users_ID的聚集索引 ) Go--在Code 上创建一个非聚集索引 Create Nonclustered Index IX_Users_Code On Users(Code Asc) Go
create index index_name on tableName(col) 這是非聚集索引還是聚集索引,如果是非聚集索引,那聚集索引怎麼建?
create index index_name on tableName(col) 是非聚集索引 create clustered index index_name on tableName(col) 是聚集索引
reate index index_name on tableName(col) 是非聚集索引 create clustered index index_name on tableName(col) 是聚集索引
--建普通索引 create index 索引名 on 表(字段) --唯一索引 create unqiue index 索引名 on 表(字段) --聚集索引create clustered index 索引名 on 表(字段)
普通索引就是非聚集索引,建非聚集索引必须在有聚集索引的前提下 create index 索引名 on 表 --这是非聚集索引 create clustered index 索引名 on 表 --这是聚集索引
CREATE index [INDEX_NAME] on table(col)
Go
If object_id('Users') Is Not Null
Drop Table Users
Go
Create Table Users
(
ID int Identity(1,1),
Code nvarchar(50),
Name nvarchar(50),
Constraint PK_Users_ID Primary Key(ID Asc)--默认会建立1个名称为 PK_Users_ID的聚集索引
)
Go--在Code 上创建一个非聚集索引
Create Nonclustered Index IX_Users_Code On Users(Code Asc)
Go
create clustered index index_name on tableName(col) 是聚集索引
create clustered index index_name on tableName(col) 是聚集索引
--建普通索引
create index 索引名 on 表(字段)
--唯一索引
create unqiue index 索引名 on 表(字段)
--聚集索引create clustered index 索引名 on 表(字段)
create index 索引名 on 表 --这是非聚集索引
create clustered index 索引名 on 表 --这是聚集索引