DELETE data from a table, joining through two tables
You need to delete rows from tt
, not individual columns:
DELETE tt FROM ItemTracker_dbo.Transaction_Type tt JOIN ItemTracker_dbo.Transaction t ON tt.Transaction_ID = t.Transaction_ID JOIN ItemTracker_dbo.Purchase p ON p.Transaction_ID = tt.Transaction_ID JOIN ItemTracker_dbo.Item i ON i.Item_ID = p.Item_ID WHERE i.Client_ID = 1
The syntax is incorrect - you don't reference columns between the DELETE
and FROM
. Use:
DELETE FROM ItemTracker_dbo.Transaction_Type tt JOIN ItemTracker_dbo.Transaction t ON tt.Transaction_ID = t.Transaction_ID JOIN ItemTracker_dbo.Purchase p ON p.Transaction_ID = tt.Transaction_ID JOIN ItemTracker_dbo.Item i ON i.Item_ID = p.Item_ID WHERE i.Client_ID = 1
To be sure you're deleting the correct stuff, I agree with wallyk that you should check the output of the SELECT statement that what is returned is what you want to remove prior to. Otherwise, perform the delete in a transaction so you can roll it back if needed.
You should compose it initially as a query to return the rows of interest. Once that's all debugged, then convert it into a delete.