Be careful.
The code you posted will not work if more than one author is deleted from the table in the same operation. That is, if I execute:
Code:
DELETE Authors WHERE State='MA';
This deletes all the authors whose state code is 'MA'. If more than one author lives in Massachusetts, you trigger will fail issuing an error message about a subquery returning more than one value...
Instead, your trigger's INSERT into your log table should read something like:
Code:
CREATE TRIGGER [LogTrig] ON [dbo].[authors]
FOR INSERT, UPDATE, DELETE
AS
INSERT INTO LogTable
(fromLine,RECID)
SELECT 'Changed State FROM ' + isnull(a.state,'<NULL>') + ' TO ' + isnull(rtrimd.state),'<NULL>') + ' BY ' + SYSTEM_USER + ' on ' + convert(char,getdate()),au_id
FROM deleted d
INNER JOIN Authors a ON a.au_id=d.au_id;
handling the case where the 'deleted' pseudo-table which is visible in the trigger contains more than one row.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com