Blog Pages

JOIN deletion to table that not in the join

DELETE dbo.TableA
FROM dbo.ViewOnTableA a
JOIN dbo.TableB b ON a.ID = b.ID
--> all the rows of dbo.TableA will be deleted!

The deleted table must be in the joins, Otherwise all the rows of the table will be deleted.

The statement above should be written:
DELETE dbo.TableA
FROM dbo.ViewOnTableA a
JOIN dbo.TableA ta ON a.ID = ta.ID
JOIN dbo.TableB b ON a.ID = b.ID

No comments:

Post a Comment