472,975 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

SQL Triggers for Auditing

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
Jul 19 '05 #1
3 3448
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"
Jul 19 '05 #2
Would copying the first 8000 characters be enough? Do you really want to
store a copy of the entire row?

I suppose if you had a replica table, and the object table had a primary
key, you could do something like this in an instead of trigger:

INSERT tableCopy SELECT col1, col2, col3 FROM objectTable WHERE pk IN
(SELECT pk FROM inserted)

But man, that performance would not be good. And, you would have to handle
the normal operation as well (since the instead of trigger stops it from
happening).

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Keith" <@.> wrote in message news:O3**************@TK2MSFTNGP10.phx.gbl...
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

Jul 19 '05 #3
Need to capture teh entire record as the data in it will be legally binding
and the slightest change could be crucial.

Performance is not too much of an issue as it will not be heavy on useage,
but the useage there is needs auditing.

"Aaron [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:eh**************@TK2MSFTNGP10.phx.gbl...
Would copying the first 8000 characters be enough? Do you really want to
store a copy of the entire row?

I suppose if you had a replica table, and the object table had a primary
key, you could do something like this in an instead of trigger:

INSERT tableCopy SELECT col1, col2, col3 FROM objectTable WHERE pk IN
(SELECT pk FROM inserted)

But man, that performance would not be good. And, you would have to handle the normal operation as well (since the instead of trigger stops it from
happening).

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Keith" <@.> wrote in message news:O3**************@TK2MSFTNGP10.phx.gbl...
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


Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cxw0106 | last post by:
Is there any way to implement File Auditing in .NET? Thanks.
3
by: John Pan | last post by:
Hi I am looking to implement an audit/history table/tables but am looking at doing this without the use of triggers. The reason for doing this is that the application is highly transactional...
1
by: BUSHII | last post by:
I have little problem and I dont have any idea how to make my trigger. I have table MyTable where I have many column with almost same name and same type (Grp1,Grp2,Grp3,Grp4...Grp50 char(1))....
3
by: Zlatko Matić | last post by:
Hello. I tried to implement audit trail, by making an audit trail table with the following fileds: TableName,FieldName,OldValue,NewValue,UpdateDate,type,UserName. Triggers on each table were...
10
by: Paulo Jan | last post by:
Hi all: Let's say I'm designing a database (Postgres 7.3) with a list of all email accounts in a certain server: CREATE TABLE emails ( clienteid INT4, direccion VARCHAR(512) PRIMARY KEY,...
0
by: RdR | last post by:
Is it true that DB2 will have an auditing tool to be used for auditing requirements such as Sarbanes-Oxley, etc? Something called Websphere Compliance Auditing? Rumours have it that IBM has a new...
4
by: Ed Rauscher | last post by:
Does ayone know what Class is used to enable Registry Auditing? Any help would be great.
14
by: Jonas | last post by:
Hi! I'm developing the middletiers of an ASP.NET application in VB.NET. I've got a business logic layer in which I would like to perform auditing to a database. Instead of making an auditing...
6
by: Rico | last post by:
Hello, I'm creating an audit table and associated triggers to be able to capture any updates and deletes from various tables in the database. I know how to capture the records that have been...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.