SQL Server FOREIGN KEY on DELETE CASCADE restrictions

Source: Internet
Author: User

It is convenient to use the ON Delete CASCADE option for FOREIGN key in the case of cascading deletions, but in the same table, if there are two foreign keys referencing the external data, you can set at most one foreign key to the on delete CASCADE. Other referential constraints require cascading deletions using triggers.

1--Create a word list2IF EXISTS (SELECT * from sysobjects WHERE name='Word')3 DROP TABLE Word4 CREATE TABLE Word5 (6WordidintNot NULL CONSTRAINT pk_word PRIMARY KEY IDENTITY (1,1),    7--Word number8Word nvarchar ( -) not NULL CONSTRAINT Uq_word UNIQUE,9--WordTen ) One GO A  ---Word Relation table -IF EXISTS (SELECT * from sysobjects WHERE name='wordrelation') the DROP TABLE wordrelation - CREATE TABLE wordrelation - ( -RelationidintNot NULL CONSTRAINT pk_wordrelation PRIMARY KEY IDENTITY (1,1),     +--Word relationship record number -WordsidintNot NULL CONSTRAINT fk_word_wordrelation_s FOREIGN KEY REFERENCES Word (wordid) on DELETE CASCADE, +--Main word number AWordoidintNot NULL CONSTRAINT fk_word_wordrelation_o FOREIGN KEY REFERENCES Word (wordid) on DELETE CASCADE, at--from the word number - ) -GO

The error reported is:

1785  - 0 5  'fk_word_wordrelation_o'wordrelation '   175005  rows cannot create a constraint. See the preceding error message. 

SQL Server FOREIGN KEY on DELETE CASCADE restrictions

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.