Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding a relationship constraint to an existing or new column in MS SQL
ALTER TABLE [dbo].[MyTable]
ADD CONSTRAINT FK_MyTable_OtherTable FOREIGN KEY (OType)
REFERENCES [dbo].[OtherTable] (Ident)
ON DELETE CASCADE
ON UPDATE CASCADE
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