SQL Server bulk removes foreign KEY constraints

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.