Sql server, cascading deletion and parent / child table

I have one simple table with the following columns: id, name and parentID

I created a relationship diagram between id and parentID (in one table), for example, a simple tree in the same table, but when I tried to cascade the user, delete it was disabled for me

I know that it will be a recursive deletion, if I delete the parent, it will delete his children.

Do I have any options for random cascading deletion without triggers?

+3
source share
3 answers

, SQL Server / .

. .

+3

.

+1

, :

  • ParentID ChildID , ParentID
  • , ID โ†’ ParentID

, , , , - .

, INNER JOIN ParentID, ChildID, Parent/Child .

Then you can start the stored procedure on any temporary basis, you want to clear any parent / child relationship where either the parent or the child does not exist. Rinse and repeat each time you run it, as a simple DELETE FROM parentchild WHERE NE (parent) OR NE (child) will not be recursive.

+1
source

Source: https://habr.com/ru/post/1717842/


All Articles