SQL Server Management Studio 更新级联
我正在开发一个简单的数据库,我希望在其中建立一对多的关系,根据我对 的理解,我创建了一个外键,该外键位于
ON UPDATE CASCADE
上在更新级联时,如果我的主表增加,引用它的其他表中的外键也将增加/具有其他表中主表的值。但问题是,当我在父表中插入数据时,另一个表中的外键没有获取我父表上主表的值,为什么会这样?我的外键如何具有与其相关的键的值?这是一个屏幕截图,供大家轻松理解
正如您所看到的 P_ID
订单表中的值没有值,即使它链接到人员表中的 P_ID
预期结果将是订单表中 P_ID
的值将相当于people 表的 P_ID,我在其中插入了数据。
I am working on a simple database where I would want to have a one is to many relationship, I've created a foreign key which has on an ON UPDATE CASCADE
, based from my understanding of ON UPDATE CASCADE
, if my Primary gets incremented the Foreign key in the other table that references it will also get incremented/ have the value of the Primary in the other table . but the problem is as I insert data in my Parent table, the foreign Key in the other table did not get the value of the Primary on my parent table why is it like that? How would my foreign key have the value of the key that is related to it? here's a screenshot for you guys to easiy understand
As you can see the P_ID
in the orders table doesn't have a value even though it is linked to the P_ID
in the People table
The Expected Result will be that in the Orders table the value of P_ID
would be equivalent to P_ID of people table, where I inserted my data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不会在插入时执行任何操作,只会在更新时执行任何操作。
如果您有 1 号人员,并且有一个给 1 号人员的订单,如果您将其更改为 2 号,则订单将更改为 2。
您可能需要一个触发器。告诉我们更多预期结果是什么
编辑:
触发示例:
You wont get any action on insert, only
on update
.If you have people number 1 and an order to people number one, if you change it to number 2, the order will be changed to 2.
You may want a trigger. tell us more what's the expected result
EDIT:
trigger example:
我认为,您误解了更新级联。请参考以下链接。
http://msdn.microsoft.com/en -us/library/aa933119%28v=sql.80%29.aspx
I think, you misunderstand ON UPDATE CASCADE. Please reference the following link.
http://msdn.microsoft.com/en-us/library/aa933119%28v=sql.80%29.aspx