I would like to see some example how to modify foreign key relationship in TSQL because it is missing here http://technet.microsoft.com/en-us/library/ms175493.aspx
Actually I want to apply delete rule Cascade.
Should it be like?
ALTER TABLE Email MODIFY
CONSTRAINT FK_EmailContact_Email
ON DELETE CASCADE
Thank you!
You cannot modify the key in a single statement, see the ALTER TABLE syntax, in which there is no ALTER CONSTRAINT available. You must use 2 ALTER TABLE statements to accomplish what you want. Delete the key in the first one using an ALTER TABLE DROP FOREIGN KEY.
To modify a foreign key. In Object Explorer, expand the table with the foreign key and then expand Keys. Right-click the foreign key to be modified and select Modify.
For our data with default specification (No Action) SQL Server would not allow an update or delete operation on referenced values of the primary key table. Since we did not define a specification for our foreign key the default No Action is used.
To delete a foreign key constraintIn Object Explorer, expand the table with the constraint and then expand Keys. Right-click the constraint and then click Delete. In the Delete Object dialog box, click OK.
I found how I can do it
GO
ALTER TABLE EmailContact DROP
CONSTRAINT FK_EmailContact_Email
GO
ALTER TABLE EmailContact ADD
CONSTRAINT FK_EmailContact_Email
FOREIGN KEY (EmailId)
REFERENCES Email (Id)
ON DELETE CASCADE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With