这样吧,如果is null 就换成id 否则就是输入的值create tigger mytrig on yourtable instead of insert as begin insert yourtable select id1, isnull(id2,id1),content from inserted end
create trigger mytrig on yourtable instead of insert as begin insert yourtable select id1, isnull(id2,id1),content from inserted end
能不能不写触发器,用SQL语句实现? 写触发器的话不好移植到其他数据库中去 谢谢
必须用触发器:create trigger mytrig on yourtable after insert as begin update yourtable set id2=id1 where exists (select 1 from inserted where inserted.id1= yourtable.id1 and yourtable.id2 is null) end
但我不知道怎么使id2和id1同步 汗............
as
begin
insert yourtable select id1, isnull(id2,id1),content from inserted
end
as
begin
insert yourtable select id1, isnull(id2,id1),content from inserted
end
写触发器的话不好移植到其他数据库中去
谢谢
as
begin
update yourtable set id2=id1 where exists (select 1 from inserted where inserted.id1= yourtable.id1 and yourtable.id2 is null)
end