Must know something of everything and everything of something!

Update触发器的冲突问题

上一篇 / 下一篇  2007-04-18 15:55:02 / 个人分类:DataBase

51Testing软件测试网)KK F M K4Y

触发器内容如下:

6N:n A uC0

SJS/?m6}0create trigger overn_xs_xsIdChange
&l~Ddt?0on dbo.xs51Testing软件测试网8PX A9El5}X!~Z*_;D
after update
-Q{&^r7G0as51Testing软件测试网'oo.ZM%_'[8T
if update(xsId)
Z%mi7aPC,~mx0  begin
C K!Kw*} Lhbt W0    declare @oldId as smallint
-B$p!OgE0    declare @newId as smallint
piF#|1cx0    select @newId=xsId from inserted51Testing软件测试网e:A v'?fOr
    select @oldId=xsId from deleted51Testing软件测试网bF2lt#QZjpL*C
  update xskc
kVt2fF6L0  setxskc.xsId=@newIdwherexskc.xsId=@oldId51Testing软件测试网 @[8q@@$`+W4CF0@3g7a
end51Testing软件测试网7par:O'bjU;z

b_~BLo w)p_GA051Testing软件测试网#sT1m2R+AAr

涉及到的表:xs(xsId,xsName),xskc(xsId,kcId,cj)51Testing软件测试网2f!Ok+W l#A~bR

51Testing软件测试网l(e^ A8L#o\s:G

update语句:update xs set xsId=5 where xsId=3

B1k&s:C^8L0

)q5m i!l1~#pz0发生错误:

?Sqgo wt`g0

T-{F:~6L,c4z0服务器: 消息 547,级别 16,状态 1,行 151Testing软件测试网/Pd#L%~%Y2x
UPDATE 语句与 COLUMN REFERENCE 约束 'FK_xskc_xs' 冲突。该冲突发生于数据库 'overn',表 'xskc', column 'xsId'。
oC2j$Z9g/Z0语句已终止。

~'D3H)X FU&B051Testing软件测试网+DK){)E FW

错误分析:xs.xsId和xskc.xsId存在主外键关系

$IH(L%XdZ051Testing软件测试网u6E? Jmw6L+W

错误解决:51Testing软件测试网(@q.[)y(f/E0hX1i

51Testing软件测试网`{,Mvm P

在表xs和xskc的关系属性中将“对INSERT和UPDATE强制关系”前的勾选去掉

eN#d*h t-[051Testing软件测试网8W;\1M._8X\5W~ sgY

再次执行update语句:

Mx [ G]EY0

!ly'd M1h }nr] l0update xs set xsId=5 where xsId=351Testing软件测试网*MZ y(R?~:\;]

51Testing软件测试网 ej1w%g$H4{ uk.y

select * from xs51Testing软件测试网2NG#h4c$a B

51Testing软件测试网 xe"mi\n+PL9H

select * from xskc

WA~:K qAY051Testing软件测试网;}N@O0qZPa

结果:xs.xsId和xskc.xsId同时被更新!

TIHo-T9Bz#f F0

y&@h'K#N5e~$X0 

uA5xeTW0
相关阅读:

TAG: 触发器 冲突 DataBase

 

评分:0

我来说两句

日历

« 2024-04-12  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 76679
  • 日志数: 93
  • 建立时间: 2007-03-22
  • 更新时间: 2007-12-31

RSS订阅

Open Toolbar