1.百度只找到这样的
--创建索引
CREATE NONCLUSTERED INDEX IX_TEST_TNAME --创建一个非聚集索引
ON TEST(TNAME) --为TEST表的TNAME字段创建索引
WITH FILLFACTOR = 30 --填充因子为30%
GO
2.我想要能在见表的时候建索引的语法,没接触过sqlserver,不知道怎么写。
你用什么版本的SQL Server,在SQL Server2014前不支持建表的脚本中创建索引,仅支持CONSTRAINT
建完表在创建索引
CREATE TABLE MyTable(
a int NOT NULL
,b smallint NOT NULL
,c smallint NOT NULL
,d smallint NOT NULL
,e smallint NOT NULL
-- This creates a primary key
,CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (a)
,CONSTRAINT IX_MyTable1 UNIQUE (b, c)
);
GO
CREATE NONCLUSTERED INDEX IX_MyTable4 ON MyTable (d, e);
GO
如果是2014,则支持同时创建索引
CREATE TABLE MyTable(
a int NOT NULL
,b smallint NOT NULL
,c smallint NOT NULL
,d smallint NOT NULL
,e smallint NOT NULL
-- This creates a primary key
,CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (a)
-- This creates a unique nonclustered index on columns b and c
,CONSTRAINT IX_MyTable1 UNIQUE (b, c)
-- This creates a non-clustered index on (d, e)
,INDEX IX_MyTable4 NONCLUSTERED (d, e)
);
GO