Monday, March 19, 2012

composite primary key

How can i implement :
Foreign key of one table referencing composite primary key of other table?Here's a sample of ours...

Check out BOL though

ALTER TABLE [dbo].[WH_Proof] ADD
FOREIGN KEY
(
[Company_Name],
[Tax_Agency_ID],
[Region],
[Tax_Class],
[Sub_Region]
) REFERENCES [dbo].[WH_Proof_List] (
[Company_Name],
[Tax_Agency_ID],
[Region],
[Tax_Class],
[Sub_Region]
),
FOREIGN KEY
(
[Company_Name],
[Tax_Agency_ID],
[Region],
[Tax_Class],
[Proof_Year],
[Proof_Period]
) REFERENCES [dbo].[Disb_Proof] (
[Company_Name],
[Tax_Agency_ID],
[Region],
[Tax_Class],
[Proof_Year],
[Proof_Period]
),
FOREIGN KEY
(
[Period_Type]
) REFERENCES [dbo].[Period_Type] (
[Period_Type]
),
FOREIGN KEY
(
[Status]
) REFERENCES [dbo].[Proof_Status] (
[Status]
)
GO|||can i define the composite foreign key while creating the table?

No comments:

Post a Comment