建立一个触发器,当表YK_NewRequirement_Sub中的字段StartDate输入数据或数据变化时判断该表当前行的Stage字段如果是“客户验证”,则将字段StartDate中的数据写入
表YK_NewRequirement中的字段FirstSubmittedDate
------解决方案--------------------
create trigger tr_YK_NewRequirement_Sub
ON YK_NewRequirement_Sub
after update,insert
as
if ((select StartDate from deleted)<>(select StartDate from inserted)) and exists(select * from inserted where Stage='客户验证')
begin
insert into YK_NewRequirement(FirstSubmittedDate)
select StartDate from inserted
end
------解决方案--------------------
use xuanya
if object_id('shu','tr') is not null
drop trigger shu
go
create trigger shu on YK_NewRequirement_Sub
after insert,update
as
begin
if(YK_NewRequirement_Sub.StartDate=inserted.StartDate) and(YK_NewRequirement_Sub.Stage='客户验证')
begin
insert into YK_NewRequirement(FirstSubmittedDate)
select StartDate from inserted
end
end