create trigger insert_inv_rzkc
on inv_rzkc
INSTEAD OF insert
as
if exists(selct top 1 * from inserted where ao008='ck01')
begin
update sal_plancomc set ax012='st0508' where sal_plancomc.ax003=inserted.ao013
end
go
on inv_rzkc
INSTEAD OF insert
as
if exists(selct top 1 * from inserted where ao008='ck01')
begin
update sal_plancomc set ax012='st0508' where sal_plancomc.ax003=inserted.ao013
end
go
on inv_rzkc
INSTEAD OF insert
as
if (select ao008 from inserted)='ck01'
begin
update sal_plancomc set ax012='st0508' where sal_plancomc.ax003=inserted.ao013
end
go
on inv_rzkc
--INSTEAD OF insert
for insert --应该是for 触发器吧? 难道你插入inv_rzkc不要它生效?
as
if exists(select * from inserted where ao008='ck01')
update sal_plancomc set ax012='st0508'
from sal_plancomc a,inserted i
where a.ax003=i.ao013 and i.ao008='ck01'
go
on inv_rzkc
INSTEAD OF insert
as
begin
update sal_plancomc
set ax012='st0508'
from sal_plancomc a join inserted b on a.ax003=b.ao013
where b.ao008='ck01'
end
go
on inv_rzkc
for insert
as
if (select ao008 from inserted)='ck01'
begin
update sal_plancomc set ax012='st0508' from sal_plancomc,inserted where sal_plancomc.ax003=inserted.ao013
end
go
运行你的代码后,提示错误:
服务器: 消息 208,级别 16,状态 1,行 1
对象名 'inserted' 无效。
create table inv_rzkc(ao008 varchar(10),ao013 varchar(10))
create table sal_plancomc(ax003 varchar(10),ax012 varchar(10))
go--触发器
create trigger insert_inv_rzkc
on inv_rzkc
--INSTEAD OF insert
for insert --应该是for 触发器吧? 难道你插入inv_rzkc不要它生效?
as
if exists(select * from inserted where ao008='ck01')
update sal_plancomc set ax012='st0508'
from sal_plancomc a,inserted i
where a.ax003=i.ao013 and i.ao008='ck01'
go--插入
insert inv_rzkc select 'ck01','ck01'
go--删除测试
drop table inv_rzkc,sal_plancomc/*--测试结果
(所影响的行数为 0 行)
(所影响的行数为 1 行)--*/