How can foreign key constraints be temporarily disabled using T-SQL?

后端 未结 16 1917
Happy的楠姐
Happy的楠姐 2020-11-22 04:57

Are disabling and enabling foreign key constraints supported in SQL Server? Or is my only option to drop and then re-create

16条回答
  •  [愿得一人]
    2020-11-22 05:44

    http://www.sqljunkies.com/WebLog/roman/archive/2005/01/30/7037.aspx

    -- Disable all table constraints
    
    ALTER TABLE MyTable NOCHECK CONSTRAINT ALL
    
    -- Enable all table constraints
    
    ALTER TABLE MyTable WITH CHECK CHECK CONSTRAINT ALL
    
    -- Disable single constraint
    
    ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint
    
    -- Enable single constraint
    
    ALTER TABLE MyTable WITH CHECK CHECK CONSTRAINT MyConstraint
    

提交回复
热议问题