[求助]触发器定位不准确
有两个表:
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表的最后一个记录的主键值
请高手指点
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表的最后一个记录的主键值
请高手指点
...全文
相关推荐
几种基本触发器之间的转换
触发器按功能分有RS、JK、D、T、T’五种类型,但最常见的集成触发器是JK触发器和D触发器。T、T’触发器没有集成产品,如需要时,可用其他触发器转换成T或T’触发器。JK触发器与D触发器之间的功能也是可以互相转换的。实际生产得出大器多为JK触发器和D触发器,由JK触发器和D触发器可构成其类型的触发器。
SQL Server 触发器 表的特定字段更新时,触发Update触发器
代码如下: create trigger TR_MasterTable_Update on MasterTable after update as if update ([Type])–当Type字段被更新时,才会触发此触发器 insert into MasterLogTable select Id ,(Case [Type] when 1 then ‘Type1’ when 2 then ‘Type2’ when 3 then ‘Type3’ when 4 then ‘Type4’ else ‘TypeDefault’ end) ,Name from inserted go 另外再补充一句
D触发器原理-D触发器电路图
D触发器原理-D触发器电路图
RS触发器和SR触发器的区别
本文主要介绍了一下RS触发器和SR触发器的区别,希望对你的学习有所帮助。
RS触发器与SR触发器区别有哪些
本文主要讲了一下关于RS触发器与SR触发器区别有哪些,希望对你的学习有所帮助。


