January 21, 2008 at 9:54 am
Anyone have an example of a trigger for insert? Really basic, just want to copy the exact row that gets inserted into a table into an audit table.
Thanks.
January 21, 2008 at 10:51 am
CREATE TRIGGER triggername
ON tablename
FOR INSERT
AS
INSERT audittable
SELECT * FROM Inserted
GO
January 21, 2008 at 11:15 am
Thanks... I managed to figured it out just had to put the column list in there and join to the live table on the key to only get the new record.
January 21, 2008 at 11:46 am
You don't have to use a trigger.
You could use the OUTPUT clause from the insert statement:
INSERT INTO TabA (Col1, Col2)
OUTPUT Inserted.Col1, Inserted.Col2 INTO TabB (Col1,Col2)
VALUES ('A','B')
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 21, 2008 at 11:48 am
Thanks... but it's a vendor app.
January 21, 2008 at 11:50 am
Well, there you go. Trigger is the trick then.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply