Tuesday, June 9, 2009

Foreign Key

Image


ALTER TABLE ChildTable
ADD CONSTRAINT LoremIpsum
FOREIGN KEY (ChildColumn) REFERENCES ParentTable (ParentColumn)


ALTER TABLE [dbo].[UserProducts]
ADD CONSTRAINT [FK_UserProducts_Users]
FOREIGN KEY (UserID) REFERENCES [dbo].[Users](UserID)

1 comment:

fc said...

ALTER TABLE TableName
ADD SomeId INT NULL CONSTRAINT [FK_TableName_TargetTable] FOREIGN KEY REFERENCES TargetTable (Id)