CREATE PROCEDURE sp_ConstraintState @TblName VARCHAR(128), @State BIT = 1 AS DECLARE @SQLState VARCHAR(500) IF @State = 0 BEGIN SET @SQLState = 'ALTER TABLE '+ @TblName + ' NOCHECK CONSTRAINT ALL' END ELSE BEGIN SET @SQLState = 'ALTER TABLE ' + @TblName + ' CHECK CONSTRAINT ALL' END EXEC (@SQLState) GO
Aufruf via
exec sp_ConstraintState 'products',0