Hello, I've implemented the following trigger:
CREATE TRIGGER [OnContactDeleted]
ON [TABLE].[Contact]
INSTEAD OF DELETE
AS
BEGIN
SET NOCOUNT ON
/*Store contact ID to variable*/
Update [TABLE].[Account] Set [PrimaryContactID] = null where [TABLE].[Account].[PrimaryContactID] = (Select ContactID from Deleted)
Delete from [TABLE].[Contact] where [TABLE].[Contact].[ContactID] = (Select ContactID from Deleted)
END
It is clear a set of foreign keys out of another table and then delete the current record. This was done because setting the foreign key to null on delete does not work.
My question is about wrapping this trigger in a try...catch block where I can roll back if an exception occurs. Is that good practice and should I be doing it for this kind of trigger?
Thanks, Jason