1

我正在使用 SQL Server 2008。我的触发器如下所示。我在两个表中插入我没有得到任何更新的值。

 CREATE TRIGGER trgAfterInserta ON AMS_33.dbo.access_event_logs
 AFTER INSERT,UPDATE 
 AS           
        declare @idams bigint;  
        declare @id int; 
        declare @uid nvarchar(20);
        declare @tentry datetime;
        declare @tsn nvarchar(20);
        declare @evtid nvarchar(20);
        declare @audit_action nvarchar(300);

select @idams   = i.id from inserted i;
select @id      =  max(Rownumber) + 1   from   TAV3.dbo.access_event_logs ;  
select @uid    =i.USERID from inserted i;   
select @tentry =i.TIMESTAMPS from inserted i;   
select @tsn   =i.TERMINALSN from inserted i;
select @evtid =i.EVENTID from inserted i;
set    @audit_action='Inserted Record -- After Insert.';
set    @tentry = dateadd(hh,3,@tentry); 


insert into TAV3.dbo.access_event_logs 
(Rownumber,Userid, Timeentry, Eventid, Terminalsn, Notes)
 values(@id,@uid, @tentry, @evtid, @tsn, @audit_action);

update AMS_33.dbo.access_event_logs set Calculated=1 where id= @idams;  

表 1 AMS_33.dbo.access_event_logs

  id    bigint  Unchecked
  USERID    nvarchar(50)    Unchecked
  DEPARTMENT    nvarchar(50)    Unchecked
  TIMESTAMPS    datetime    Unchecked
  EVENTID   nvarchar(50)    Unchecked
  TERMINALSN    nvarchar(50)    Unchecked
  ACCESSMETHOD  nvarchar(255)   Unchecked
  REMARKS   nvarchar(255)   Unchecked
  TERMINALIP    nvarchar(50)    Unchecked
  PHOTO image   Checked
  PHOTOSIZE int Unchecked
  RECLOGDTM datetime    Unchecked
  RECLOGFROMIP  nvarchar(50)    Unchecked
  LOCALTIMESTAMP    datetime    Unchecked
  PhotoPath nvarchar(50)    Checked
  Calculated    int Checked

表 2 TAV3.dbo.access_event_logs

Rownumber   int Unchecked
Userid  nvarchar(20)    Unchecked
Timeentry   datetime    Unchecked
Eventid nvarchar(20)    Checked
Terminalsn  nvarchar(20)    Unchecked
Calculated  int Checked
Notes   nvarchar(300)   Checked

这里没有插入或更新正在执行?

4

1 回答 1

1

您假设在 select @idams = i.id from inserted i; 等语句中只插入或更新了一行。

那可能是假的。然后这些语句将永远无法插入

于 2012-09-27T11:45:52.997 回答