SQL Server CREATE TABLE 문 내에서 기본 키 또는 고유 인덱스를 만들 수 있습니다. CREATE TABLE 문 내에서 고유하지 않은 인덱스 를 만들 수 있습니까?
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
다시 말하지만, 목표는 CREATE TABLE 문 뒤가 아니라 내에서 고유하지 않은 인덱스를 만드는 것입니다.
그만한 가치가있는 [CREATE TABLE에 대한 SQL Server 온라인 설명서 항목]을 찾지 못했습니다 . 이 도움 .
또한 [This Question] 은 거의 동일하지만 수락 된 답변은 적용되지 않습니다.