Click here to Skip to main content
15,441,149 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi how can i cascade delete on self referencing table in ms sql server? im using C# , i have table Category #id name parent_id and i want every time user delete a parent category , childs categories also delete, sql server dont let me to change the update or insert rule for self refrencing table , whether i have to use trigger or CTE?

1 solution

Drop your existing FK constraint on Child Categories and recreate the FK but add a ON DELETE CASCADE.
Share this answer
HDM91 29-Aug-14 6:42am     CRLF
i get an error : Introducing FOREIGN KEY constraint 'FK_Category_Category' on table 'Category' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900