I am currently trying to write a trigger that when an insert or update is made to a table, it inserts a copy of the row into a log table. It currently works when one row is inserted, but it will error if you try to do multiple inserts or modifies to the same table. Do I need a loop to do this, or what do you guys suggest? My code is as follows. Thanks!
CREATE TRIGGER trgTestLogging
ON dbo.test
FOR INSERT, UPDATE
AS
DECLARE @productID int
SELECT @productID = (SELECT productid FROM INSERTED)
DECLARE @name VARCHAR(255)
SELECT @name = (SELECT name FROM INSERTED)
DECLARE @logdate datetime
SELECT @logdate = (SELECT logdate FROM INSERTED)
DECLARE @uptype varchar(50)
SELECT @uptype = (SELECT uptype FROM INSERTED)
INSERT INTO test_log(productid, name, logdate, uptype) VALUES(@productID, @name, @logdate, @uptype)