1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| DECLARE @NomTable NVARCHAR(200), @NomContrainte VARCHAR(200) ,@REQ_SQL NVARCHAR(500)
DECLARE TableList CURSOR FOR SELECT o.name nomtable,
so.name nomcontrainte
FROM sysobjects o
INNER JOIN sysforeignkeys sf
ON o.id = sf.fkeyid
INNER JOIN sysobjects so
ON so.id = sf.constid
WHERE o.xtype = 'U'
OPEN TableList
FETCH TableList INTO @NomTable, @NomContrainte
WHILE @@Fetch_Status = 0
BEGIN FETCH TableList INTO @NomTable, @NomContrainte
select @REQ_SQL= 'ALTER TABLE ['+@NomTable+ '] NOCHECK CONSTRAINT '+@NomContrainte
print @REQ_SQL
EXEC (@REQ_SQL)
END
CLOSE TableList |
Partager