[求助]触发器定位不准确
有两个表:
test1:
create table test1(
yy varchar(50) primary key
gg
)
create table temp1(
yy varchar(50) primary key
)
我建立一触发器,功能是:更新表test1的gg字段内容,找到test1更新记录
所对应的主键yy,在表temp1中,寻找是否存在此主键,如果存在,不进行更新
如果不存在,则插入此主键值到表temp1
触发器为:
REATE TRIGGER updateto ON [dbo].[test1]
FOR instead of update
AS
declare @t_yy as varchar(50)
declare @t_gg as varchar(50)
declare @t_row as varchar(50)
begin
select @t_yy=yy,@t_gg=gg from test1
delete from temp1 where yy=@t_yy
insert into temp1 select a.yy from test1 a where a.yy=@t_yy
end
但是,运行结果:
temp1表中只插入test1表的最后一个记录的主键值
请高手指点