I want to abandon all the table restrictions that I have. Since this is not possible in SQL Server, I created a script (based on something found on the network) that dynamically creates reset instructions as a result of the selection:
SELECT 'ALTER TABLE ' + TABLE_SCHEMA + '.[' + TABLE_NAME + '] DROP CONSTRAINT [' + CONSTRAINT_NAME + ']'
FROM information_schema.table_constraints
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
AND TABLE_NAME LIKE 'Old_%''
This is done; I cannot find how to parse it and execute it in a loop.
My attempt is to create such a cursor, but I have no hint for it to execute each line:
DECLARE @AlterTables nvarchar(2000)
SET @AlterTables = 'DECLARE Dyn_cursor CURSOR
FOR SELECT ''ALTER TABLE '' + TABLE_SCHEMA + ''.['' + TABLE_NAME + ''] DROP CONSTRAINT ['' + CONSTRAINT_NAME + '']''
FROM information_schema.table_constraints
WHERE CONSTRAINT_TYPE = ''FOREIGN KEY''
AND TABLE_NAME LIKE ''Old_%'''
Exec(@AlterTables)
Open Dyn_Cursor
FETCH NEXT FROM Dyn_Cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
END
Close Dyn_cursor
Deallocate Dyn_cursor
Thank you in advance for having a solution for this!
amuses
J.
source
share