聚集索引是指索引序列与表中行的排列顺序一致,组合索引是指建立在多列上的索引. CREATE TABLE tb(id int NOT NULL PRIMARY KEY CLUSTERED, col nchar(10) NULL )ON [PRIMARY] --在建表的同时创建了作为主键的聚集索引,基于id列 GO drop table tb go CREATE TABLE tb( id int NULL, col nchar(10) NULL ) ON [PRIMARY] GO CREATE CLUSTERED INDEX IX_tb ON dbo.tb(id) --单独创建聚集索引 ix_tb,基于 id 列. go drop table tb go CREATE TABLE tb( id1 nvarchar(50) NOT NULL, id2 nvarchar(50) NOT NULL, col nchar(10) NULL CONSTRAINT PK_tb PRIMARY KEY CLUSTERED(id1,id2) ) ON [PRIMARY] --在建表的同时创建了作为主键的聚集索引,基于id1,id2两列 GO drop table tb go CREATE TABLE tb( id1 varchar(10) NOT NULL, id2 varchar(10) NOT NULL, col nchar(10) NULL ) ON [PRIMARY] GO CREATE CLUSTERED INDEX IX_tb ON dbo.tb(id1,id2) --单独创建聚集索引 ix_tb,基于 id1,id2 两列. go drop table tb --如果不想作为聚集索引,把上面的 CLUSTERED 拿掉就行了
create table test_index ( stuID int primary key, stuName char(10), stuClass tinyint, stuGender bit, stuAddress varchar(100) ) --组合索引 Create index student on test_index (stuName,stuClass) --聚集索引 CREATE CLUSTERED INDEX ClusteredIndex ON TableName (stuname);
--聚集索引 CREATE CLUSTERED INDEX idx_name ON tb(col) --组合索引 CREATE INDEX idx_name ON tb(col1,col2)
CREATE TABLE tb(id int NOT NULL PRIMARY KEY CLUSTERED,
col nchar(10) NULL
)ON [PRIMARY]
--在建表的同时创建了作为主键的聚集索引,基于id列
GO
drop table tb
go
CREATE TABLE tb(
id int NULL,
col nchar(10) NULL
) ON [PRIMARY]
GO
CREATE CLUSTERED INDEX IX_tb ON dbo.tb(id)
--单独创建聚集索引 ix_tb,基于 id 列.
go
drop table tb
go
CREATE TABLE tb(
id1 nvarchar(50) NOT NULL,
id2 nvarchar(50) NOT NULL,
col nchar(10) NULL
CONSTRAINT PK_tb PRIMARY KEY CLUSTERED(id1,id2)
) ON [PRIMARY]
--在建表的同时创建了作为主键的聚集索引,基于id1,id2两列
GO
drop table tb
go
CREATE TABLE tb(
id1 varchar(10) NOT NULL,
id2 varchar(10) NOT NULL,
col nchar(10) NULL
) ON [PRIMARY]
GO
CREATE CLUSTERED INDEX IX_tb ON dbo.tb(id1,id2)
--单独创建聚集索引 ix_tb,基于 id1,id2 两列.
go
drop table tb
--如果不想作为聚集索引,把上面的 CLUSTERED 拿掉就行了
(
stuID int primary key,
stuName char(10),
stuClass tinyint,
stuGender bit,
stuAddress varchar(100)
)
--组合索引
Create index student on test_index (stuName,stuClass)
--聚集索引
CREATE CLUSTERED INDEX ClusteredIndex ON TableName (stuname);
--聚集索引
CREATE CLUSTERED INDEX idx_name ON tb(col)
--组合索引
CREATE INDEX idx_name ON tb(col1,col2)