触发器简单问题
create table xs
(xsnum int primary key,
xsname varchar(20) not null,
xssex varchar(2) not null)
create table kc
(xsnum int foreign key references xs(xsnum),
xsname varchar(20) not null,
kcnum int null,
kcname varchar(20) null)
写了个update触发器
CREATE TRIGGER [trixs] ON [dbo].[xs]
FOR update
AS
begin
if update(xsnum) or update (xsname)
update kc set xsnum=i.xsnum,xsname=i.xsname from inserted i,deleted d where kc.xsnum=d.xsnum
end
为什么我修改xs表中的xsnum,xsname时kc表只修改了xsnum而没修改到xaname?
谢谢
------解决方案--------------------修改xs表中的xsnum时, 如果kc表中的xsnum有外键引用时会报错吧
------解决方案----------------------这样做就可以了(经测试)
CREATE TRIGGER [trixs] ON [dbo].[xs]
FOR update
AS
begin
if update(xsnum) or update(xsname)
update kc set xsnum=i.xsnum ,xsname=i.xsname from kc ,inserted i,deleted d where kc.xsnum=d.xsnum and kc.xsname=d.xsname
end