可以在 SQLServerCREATETABLE 语句中创建主键或唯一索引。是否可以在 CREATETABLE 语句中创建 非唯一性索引?
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)
-- Is it possible to create a non-unique index on columns d and e here?
-- Note: these variations would not work if attempted:
-- ,CONSTRAINT IX_MyTable2 INDEX (d, e)
-- ,CONSTRAINT IX_MyTable3 NONCLUSTERED INDEX (d, e)
);
GO
-- The proposed non-unique index should behave identically to
-- an index created after the CREATE TABLE statement. Example:
CREATE NONCLUSTERED INDEX IX_MyTable4 ON MY_TABLE (d, e);
GO
同样,目标是在 CREATETABLE 语句中创建非唯一索引,而不是在它之后创建。
不管怎样,我觉得 [ SQLServer 为 CREATETABLE 联机丛书条目]没什么帮助。
Also, [这个问题] is nearly identical, but the accepted answer does not apply.