Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scripting an UPDATE action TRIGGER 1

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
Hopefully I'm just missing the obvious with this one ....
Using the SQL Server 7.0 Books On-Line Help files I've successfully set up triggers for the INSERT and DELETE actions against a table Table1 (making an appropriate time-stamped entry in a log table Table1_2) but now need to do the same for the UPDATE action against Table1 entries. Can anyone give me a pointer how I should be doing this ?

The INSERT/DELETE action triggers are detailed here :

CREATE TRIGGER [Table1_TRG_1] ON dbo.Table1
FOR INSERT
AS
INSERT INTO [Table1_2]
([DtAction], [Action], [Field1], [Field2], [Field3], [Field4])
SELECT
GetDate(), 'NEW', ins.[Field1], ins.[Field2], ins.[Field3], ins.[Field4]
FROM inserted ins

CREATE TRIGGER [Table1_TRG_2] ON dbo.Table1
FOR DELETE
AS
INSERT INTO [Table1_2]
([DtAction], [Action], [Field1], [Field2], [Field3], [Field4])
SELECT
GetDate(), 'DLT', dlt.[Field1], dlt.[Field2], dlt.[Field3], dlt.[Field4]
FROM deleted dlt

Thanks in advance.
Steve
 
CREATE TRIGGER [Table1_TRG_1] ON dbo.Table1
FOR update as
--put whatever code you need here.

The inseted pseudo-table will have the new data, the deleted pseudo-table will have th old data.

 
Flueplr : I tried something like that following the logic of the other two given examples but had an error on using the final bit '.... FROM updated upd' - should this work ?
 
There is no updated psuedo table. As I said in the previous response. Inserted has the new (updated) data, deleted has the old data.

 
Thanks for the explanation of this - it's proved helpful to me. I've now got the required Triggers set up against the table.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top