Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trigger -> Auditing purposes

Author  Topic 

SQLError
Yak Posting Veteran

63 Posts

Posted - 2004-08-10 : 16:33:39
Hi, I have gone though the examples and I am still confused.

I have 2 tables, T1 and T2
T1 = (recordID,data1,data2)
T2 = (data1,data2)

Basically, when a row is entered into T1, or updated, I want the previous state of the row (data1 and data2) to be stored in
T2. I can't seem to get a trigger for this to work.

I have

CREATE TRIGGER [Trigger] ON [dbo].[Table_1]
FOR INSERT, UPDATE
AS

INSERT INTO Table_2 (data1,data2)
SELECT data1,data2 FROM Table_1 WHERE
Table_1.RecordID = RecordID


I know, its probably way off.

thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-08-10 : 17:15:41
For inserts, there is no previous state. Right? For updates:

CREATE TRIGGER [Trigger] ON [dbo].[Table_1]
FOR UPDATE
AS

INSERT INTO Table_2 (data1,data2)
SELECT data1,data2 FROM deleted


deleted table contains the old information. inserted table would contain the new information.

Tara
Go to Top of Page
   

- Advertisement -