我有一个简单的触发器,当用户在表中插入行时运行。
由于还可以进行批量插入并且插入顺序很重要,有没有办法在触发器中保留它?
可以这样做还是有更好的方法来做到这一点?
ALTER TRIGGER simpleTrigger
ON shop
AFTER INSERT AS
SELECT * INTO #orderedInserted from inserted i ORDER BY i.Emp_Sal
declare @empid int;
declare @empname varchar(100);
declare @empsal decimal(10,2);
declare @audit_action varchar(100);
select @empid=#orderedInserted.Emp_ID from inserted i;
select @empname=#orderedInserted.Emp_Name from inserted i;
select @empsal=#orderedInserted.Emp_Sal from inserted i;
set @audit_action='Inserted Record -- After Insert Trigger.';
insert into Employee_Test_Audit
(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
values(@empid,@empname,@empsal,@audit_action,getdate());
GO;