Delete Internal Connection in SQL Server 2008?

I am trying to join two tables together and delete on it.

DELETE TableA FROM TableA a INNER JOIN TableB b on b.Id = a.Id where title like 'test' 

Above was what I came up with, but I keep getting

DELETE statement contrary to REFERENCE constraint

I thought that if I join the two tables together, I would delete both at the same time, and no restrictions would conflict.

Am I missing something in my request?

+6
source share
3 answers

First try removing TableB with a header condition. Then delete these entries in TableA

 DELETE FROM TableB WHERE Id IN ( SELECT Id FROM TableA WHERE title = 'test') DELETE FROM TableA WHERE title = 'test' 

Link restrictions block you from deleting rows in TableA when you still have a link in TableB

+6
source

try the following:

 DELETE TableA FROM TableA INNER JOIN TableB b on b.Id = TableA.Id where TableA.title like 'test' 
+12
source

I would delete one by one with a cascading restriction.

0
source

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


All Articles