Deshabilitar/Habilitar Constraint SQL Server.

-- Disable all table constraints

ALTER TABLE MyTable NOCHECK CONSTRAINT ALL

-- Enable all table constraints

ALTER TABLE MyTable CHECK CONSTRAINT ALL

-- Disable single constraint

ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint

-- Enable single constraint

ALTER TABLE MyTable CHECK CONSTRAINT MyConstraint
Anuncios

SNIPPET – Traer el código fuente de algunos objetos en las bases

--@Author: Diegoxfs

DECLARE @OBJETO VARCHAR(MAX)
DECLARE TODOS CURSOR FOR
SELECT NAME FROM SYS.OBJECTS WHERE TYPE = 'TR'
OPEN TODOS
FETCH NEXT FROM TODOS
INTO @OBJETO
WHILE @@FETCH_STATUS = 0
BEGIN	
SELECT O.name, C.TEXT
FROM SYSCOMMENTS C
INNER JOIN SYS.OBJECTS O
ON C.ID=O.OBJECT_ID
WHERE O.NAME =@OBJETO
FETCH NEXT FROM TODOS INTO @OBJETO
END
CLOSE TODOS
DEALLOCATE TODOS