Re: Audit trails for changed records
From: CD (mcdye1@hotmail.com)
Date: 08/08/02
- Next message: James Luetkehoelter: "Re: Compromised SQL Server"
- Previous message: John Kraeck: "SQL7 sp4 and Network Connections"
- In reply to: lindawie: "Re: Audit trails for changed records"
- Next in thread: lindawie: "Re: Audit trails for changed records"
- Reply: lindawie: "Re: Audit trails for changed records"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "CD" <mcdye1@hotmail.com> Date: Thu, 8 Aug 2002 15:35:09 -0500
How would you code it to ignore it if C3 changed, but you still wanted the
record if C1 or C2 was touched?
"lindawie" <lindawie@my-deja.com> wrote in message
news:uxwz2LvPCHA.2688@tkmsftngp11...
> Sue,
>
> > Hi I am using SQL 7.0 and MS Access. I would like to be
> > able to log to a table information whenever a record is
> > changed.
> >
> > What's the best way of doing that?
> >
> > I can track the transactions with the profiler by tracing
> > all RPC:completed events with the txt begining with
> > sp_executesql.
> >
> > I would like to have the info in a table I can view in
> > access.
>
> The easiest way it to do this through a trigger.
> Create a history table that has the same structure as the
> table you want to audit, plus an additional column for the
> primary and perhaps a timestamp column.
>
> In your trigger, insert from the deleted rtable into the
> history table. The main table contacts the current data and
> the history table conatins all past data. A union of main table
> and history table gives you a complete picture of all activity.
>
>
> create table t1(c1 int, c2 int)
> create table t1_hist (c0 int identity, c1 int, c2 int,
> moddate datetime default getdate())
> go
> create trigger tr_trg on t1 for update, delete
> as
> insert t1_hist (c1, c2) select c1, c2 from deleted
> go
> insert t1 select 1, 1 union select 2, 2 union select 3, 3
> select * from t1
> update t1 set c2 = c2 * 10 where c1 > 1
> delete t1 where c1 = 2
> select * from t1
> select * from (
> select c0, c1, c2, moddate from t1_hist
> union all
> select null, c1, c2, null from t1) hist
> order by c1, moddate
> go
> drop table t1
> drop table t1_hist
>
>
> Linda
>
>
- Next message: James Luetkehoelter: "Re: Compromised SQL Server"
- Previous message: John Kraeck: "SQL7 sp4 and Network Connections"
- In reply to: lindawie: "Re: Audit trails for changed records"
- Next in thread: lindawie: "Re: Audit trails for changed records"
- Reply: lindawie: "Re: Audit trails for changed records"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|