Monday, June 27, 2011

EnableDisable Constraints

A quick way to generate script to disable all FK constraints in current db: SELECT 'ALTER TABLE ' + B.name + ' NOCHECK CONSTRAINT ' + C.name FROM sysconstraints A , sysobjects B , sysobjects C WHERE A.id = B.id AND A.constid = C.id AND C.type = 'F' A quick way to generate script to enable all FK constraints in current db: SELECT 'ALTER TABLE ' + B.name + ' CHECK CONSTRAINT ' + C.name FROM sysconstraints A , sysobjects B , sysobjects C WHERE A.id = B.id AND A.constid = C.id AND C.type = 'F'

No comments:

Post a Comment