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