Created
March 24, 2016 14:36
-
-
Save tekiegirl/7018182e92f0e5ce53b2 to your computer and use it in GitHub Desktop.
Adding a relationship constraint to an existing or new column in MS SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE [dbo].[MyTable] | |
ADD CONSTRAINT FK_MyTable_OtherTable FOREIGN KEY (OType) | |
REFERENCES [dbo].[OtherTable] (Ident) | |
ON DELETE CASCADE | |
ON UPDATE CASCADE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE [dbo].[MyTable] (Ident int NOT NULL, Name nvarchar(50), OType int | |
CONSTRAINT PK_MyTable PRIMARY KEY NONCLUSTERED (Ident), | |
CONSTRAINT FK_MyTable_OtherTable FOREIGN KEY (OType) | |
REFERENCES [dbo].[OtherTable] (Ident) | |
ON DELETE CASCADE | |
ON UPDATE CASCADE | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment