100分,table1 采用 Update触发器,如何用最简单的方式识别改了哪个字段,并记日志
table1   采用   Update触发器,如何用最简单的方式识别改了哪个字段,并记日志   
 用户要求,只把改了字段值的日志记下来,不需要全部都记   
 因为一个表为   近   50个字段,求一个最简单的实现方式   
 就是如何比较临时表   Deleted   Inserted      
 只把其中有改动的字段记录下来 
 如 
 字段名   修改前值   修改后值   修改时间   
------解决方案--------------------create trigger tr_table1_update 
 on table1 
 for update 
 as 
 set nocount on    
 insert 日志(字段名,修改前值,修改后值,修改时间) 
 select  'col1 ' as 字段名,d.col1,i.col1,getdate 
 from inserted i,deleted d 
 where i.id=d.id 
 and not (i.col1=d.col1 or i.col1 is null and d.col1 is null)   
 insert 日志(字段名,修改前值,修改后值,修改时间) 
 select  'col2 ' as 字段名,d.col1,i.col1,getdate 
 from inserted i,deleted d 
 where i.id=d.id 
 and not (i.col2=d.col2 or i.col2 is null and d.col2 is null)   
 ...   
 go     
------解决方案--------------------字段名 修改前值 修改后值 修改时间 
 ---------------- 
 还应该加一个主键值吧,要不然知道改的是哪一条?