Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (27 sloc) 1.04 KB
IF EXISTS (SELECT * FROM sys.tables WHERE object_id = OBJECT_ID(N'[dbo].[PKTest_FK1]')) DROP TABLE PKTest_FK1;
IF EXISTS (SELECT * FROM sys.tables WHERE object_id = OBJECT_ID(N'[dbo].[PKTest_FK2]')) DROP TABLE PKTest_FK2;
IF EXISTS (SELECT * FROM sys.tables WHERE object_id = OBJECT_ID(N'[dbo].[PKTest_Main]')) DROP TABLE PKTest_Main;
CREATE TABLE PKTest_Main
(
Field1 int
,Field2 int
,Field3 int
,Field4 int
,CONSTRAINT [PK_Name_Goes_Here] PRIMARY KEY NONCLUSTERED (Field1 asc, Field2 asc)
)
CREATE CLUSTERED INDEX [IX_Clustered_Composite] ON [PKTest_Main] (Field2 asc, Field3 asc)
CREATE NONCLUSTERED INDEX [IX_PKTest_Main_Field2_Field3] ON [PKTest_Main] (Field3 asc, Field4 asc)
CREATE TABLE PKTest_FK1
(
Field1 int
,Field2 int
,Field3 int
,CONSTRAINT [PKTest_FK1_FK] FOREIGN KEY (Field2, Field3) REFERENCES PKTest_Main(Field1,Field2)
)
CREATE TABLE PKTest_FK2
(
Field1 int
,Field2 int
,Field3 int
,CONSTRAINT [PKTest_FK2_FK] FOREIGN KEY (Field1, Field2) REFERENCES PKTest_Main(Field1,Field2)
)