DECLARE @SQLSTR VARCHAR;D eclare my_cursor Cursor--Defines the cursor for (select drop CONSTRAINT' +fk.name+ ' ; ' As Command from sys.foreign_keys FK JOIN sys.all_objects o on fk.parent_ OBJECT_ID=O.OBJECT_ID)--isolate the desired set into the cursor OPEN my_cursor; --Open cursor FETCH NEXT from my_cursor to @SQLSTR; --Reads the first row of data while @ @FETCH_STATUS = 0 BEGIN exec (@SQLSTR); --update dbo. Memberaccount SET UserName = UserName + ' A ' WHERE current of my_cursor; --Update --delete from dbo. Memberaccount WHERE Current of my_cursor; --delete the FETCH next from the my_cursor into @SQLSTR;--Read the next line of data END close my_cursor;--close cursor deallocate my_cursor;--Release cursor GO
If you delete the record you can NOCheck CONSTRAINT
If it is to delete the table, Nocheck seems to be no, must drop CONSTRAINT
SQL Server bulk removes foreign KEY constraints