Wednesday, November 12, 2008

How to add a foreign key constraint in t-sql

The WITH NOCHECK clause is not recommended since future table updates could fail as the contstraint is re-validated, but I needed it to get it to work on some tables and will have to deal with the missing data later.



ALTER TABLE dbo.SKU_Price WITH NOCHECK ADD CONSTRAINT
FK_SKU_Price_PriceGroupID FOREIGN KEY
(
PriceGroupID
)
REFERENCES dbo.SKU
(
rid
)
ON UPDATE NO ACTION
ON DELETE NO ACTION

No comments: