日期:2014-05-18  浏览次数:20520 次

大家好,本人有一个关于SQL Server 2000触发器的问题请教
大家好,本人有一个关于SQL Server 2000触发器的问题请教,如下:

1.分别有Employees表和Log表;
2.Employees表里面有Employeeid,Technical字段,
3.Log表里面有Employeeid,Date,OldTechnical,NewTechnical字段,

问题:
当Employees表里面的Technical字段更新时,就在Log表里面的Date字段插入更改日期,OldTechnical字段插入原Technical,NewTechnical字段插入更新后的Technical.

感谢!!!

------解决方案--------------------
SQL code
create trigger triTest on Employees
for update
as
if update(Technical)
    insert Log  select a.create trigger triTest on Employees
for update
as
if update(Technical)
    insert Log  select a.Employeeid,getdate(),a.Technical,b.Technical from deleted a,inserted b where a.Employeeid=b.Employeeid

------解决方案--------------------
SQL code
create trigger triTest on Employees
for update
as
if update(Technical)
    insert Log  select a.Employeeid,getdate(),a.Technical,b.Technical from deleted a,inserted b where a.Employeeid=b.Employeeid

------解决方案--------------------
SQL code

--当Employees表里面的Technical字段更新时,就在Log表里面的Date字段插入更改日期,OldTechnical字段插入原
--Technical,NewTechnical字段插入更新后的Technical. 

create trigger 触发器名 on Employees
after update
as
begin
insert into log
select a.Employeeid,getdate(),b.Technical,a.Technical 
from inserted a left join deleted b
on a.Employeeid=b.Employeeid

end