此触发器中的问题在哪里?

时间:2017-06-07 10:17:47

标签: sql-server tsql

我需要你的专家观察来使这个触发器工作。

我有3个表格,Create_Event是主要的,第二个(events_status)是状态表,第三个(event_history)一个是'备份表'。

我只想跟踪每个事件,因为状态已更新为“已完成”状态。也想从主表中删除相同的行但我不想丢失它直到我有一个曲目。

所以,这就是我正在尝试的东西..但它的删除部分无效。

ALTER TRIGGER trgUpdhistory on Events_Status for update    
as  
declare @status varchar(255)  
BEGIN  
set xact_abort on  
    select @status=status from inserted  

if (@status = 'Completed')          
    begin  try        
    begin tran   

 insert into Event_History          
 select * from Create_Event          
 where exists(select * from create_event D left join inserted E on D.ID=E.CE_Ids)        

 delete from Create_Event  
 where exists(select * from create_event D left join deleted E on D.ID=E.CE_Ids)  
COMMIT  
end try          

begin catch    
    ROLLBACK  
    RAISERROR ('Transaction is not completed',16,1)         
end catch           

END

0 个答案:

没有答案
相关问题