เป็นไปได้ที่จะสร้างคีย์หลักหรือดัชนีเฉพาะภายในคำสั่ง 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 ไม่ใช่หลังจากนั้น
สำหรับสิ่งที่คุ้มค่าฉันไม่พบว่า[รายการ SQL Server Books Online สำหรับ CREATE TABLE]จะเป็นประโยชน์
นอกจากนี้[คำถามนี้]เกือบจะเหมือนกัน แต่คำตอบที่ยอมรับจะใช้ไม่ได้