Re: SQL Triggers for Auditing
From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 06/24/04
- Next message: ou812_at_ou812.com: "Re: Cookies in global.asa"
- Previous message: Don Wash: "CGI and ASP Mix"
- In reply to: Keith: "SQL Triggers for Auditing"
- Next in thread: Aaron [SQL Server MVP]: "Re: SQL Triggers for Auditing"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Jun 2004 16:37:42 -0400
Keith wrote:
> Not sure if anyone in here knows the answer to this, but I asked in a
> SQL group and haven't had a suitable answer and since the front end
> app is ASP I though I'd give here a try.
>
> I am trying to create a simple trigger in my SQL DB so that when a
> record is updated or deleted a copy of the original record is placed
> in an audit table.
>
> However, I keep getting the following error:
>
> Server: Msg 311, Level 16, State 1, Procedure
> SYS_Individual_AUDIT_Trigger, Line 9
> Cannot use text, ntext, or image columns in the 'inserted' and
> 'deleted' tables.
>
> Now apparently this is because the TEXT column I have cannot be
> 'logged' or so someone told me.
>
> Is there any way of using a trigger (an idiot proof way) so that I
> can copy a record to an audit table when it is updated/deleted if the
> record contains one or more TEXT columns?
>
> If all else fails I will write it into my app but I am trying to
> avoid that if possible.
>
> Thanks
If you are using SQL 2000, you can use an "Instead Of" trigger. Normal
trigger fire after the triggering action occurs, so the only place to find
the old data is in the deleted table. Instead Of triggers fire before the
triggering action is performed, allowing you to perform some activity
instead of the activity that would have been performed by the triggering
action. look it up in SQL BOL (SQL Books Online) and post any follow-up
questions you have to m.p.sqlserver.programming.
If pre-SQL7, then you have no recourse but to perform all updates and
deletions via stored procedures which copy the original data to the audit
table before performing the intended action.
HTH,
Bob Barrows
-- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
- Next message: ou812_at_ou812.com: "Re: Cookies in global.asa"
- Previous message: Don Wash: "CGI and ASP Mix"
- In reply to: Keith: "SQL Triggers for Auditing"
- Next in thread: Aaron [SQL Server MVP]: "Re: SQL Triggers for Auditing"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|