2017年12月22日 星期五

[MS SQL]停用/啟用 Foreign Key

-- Disable all table constraints

ALTER TABLE [table_name] NOCHECK CONSTRAINT ALL

-- Enable all table constraints

ALTER TABLE [table_name] WITH CHECK CHECK CONSTRAINT ALL

-- Disable single constraint

ALTER TABLE [table_name] NOCHECK CONSTRAINT [fk_name]

-- Enable single constraint

ALTER TABLE [table_name] WITH CHECK CHECK CONSTRAINT [fk_name]

https://stackoverflow.com/questions/159038/how-can-foreign-key-constraints-be-temporarily-disabled-using-t-sql

沒有留言: