fiogf49gjkf0d I'm having difficulties with the UPDATE statement in my trigger. The trigger is fired after DELETE on the sysdba.ACCOUNT table. It INSERTs to an audit table that basically tracks deleted accounts. There is a similar auditing table for changes to contacts, and I would like to update this table to reflect that its parent account has been deleted.
CREATE TRIGGER [sysdba].[tr_AccountDelete]<br /> ON [sysdba].[ACCOUNT] AFTER DELETE AS IF @@ROWCOUNT > 0 BEGIN SET NOCOUNT ON DECLARE @Date DATETIME SET @Date = GETDATE() INSERT INTO Audits (id, table_name, date, row_deleted) SELECT ACCOUNTID, 'ACCOUNT', GETDATE(), 'ACCOUNTID:' + acct.ACCOUNTID + ' ACCOUNT:' + ISNULL(acct.ACCOUNT, '') + ' MAINPHONE:' + ISNULL(acct.MAINPHONE, '') FROM DELETED AS acct; UPDATE ContactAudits SET parent_state = 'DELETED' WHERE parent_id IN (SELECT ACCOUNTID FROM DELETED) END SET NOCOUNT OFF
The INSERT statement should be free of errors. As far as I can tell the UPDATE statement is the problem since the trigger will succeed without it. |