I have a question regarding SQL triggers. I am using MS SQL.
I have two tabels.
TableA consists of two fields
table_B_Id and table_A_uniqe_Id (Primary key)
TableB consists of two similar fields:
name and table_B_unique_Id (Primary key)
Table A contains several rows that references the same TableB row. So the relation is: TableA(n) <---->TableB(1)
Now I would like to create a DELETE trigger on TableA which will do:
-After a row is deleted from TableA it checks in TableA if there are any other rows that has the same table_B as the one that was deleted. And if so it deletes the row in Table B which has [Deleted Row] in TableA.Table_B_Id == TableB. table_B_unique_Id
CREATE TRIGGER Trigger1
IF EXISTS (SELECT * FROM TableA WHERE deleted.table_B_Id == table_B_Id)
DELETE FROM TableB WHERE deleted.table_B_Id == table_b_unique_Id
but this does not work at all :-)
any help is highly apprechiated.