Hi All,
I have 4 tables Table1, Table2, Table3, Table4. Whenever data is inserted in Table1, data is also insert in Table4. Similarly When data is inserted in Table2, and Table3 data is also insert in Table4. so we cannot create Foreign key on Table4.
so Please tell me, how to create trigger on Table1, Table2 and Table3 to preserve rows to delete it. if it is exists in Table4.
Thanks in advance.
What I have tried:
Create trigger trgDeleteDebitVoucher on TblDebitVoucher For Delete
As
IF EXISTS (SELECT * FROM TblStatement Where ProjectNo In (Select NoteNo From TblDebitVoucher))
BEGIN
RAISERROR ('This Voucher is used in Statement Table, So Cannot Delete It.', 16, 1);
ROLLBACK TRANSACTION;
END;