更新表依赖于另一个表 [英] updating table dependent on another table

查看:105
本文介绍了更新表依赖于另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表CostSheets和表凭单,这些表的外键是CostSheets的主键,它们之间的关系是一对多的.
我想执行以下
-如果我更新CostSheets,则代金券的集合也会更新
因为在DataAccessLayer中,CostSheets具有凭证的集合
当我更新CostSheets时,代金券的集合已更新或
当我删除CostSheets时,将删除凭证的集合

i have table CostSheets and table Vouchers that has aforeign key which is the primary key of CostSheets and the relation between them is one to many
i want to do the following
- if i update CostSheets the collection of Vouchers is updated
because in DataAccessLayer CostSheets has acollection of Vouchers
while i update CostSheets the collection of Vouchers is updated or
while i delete CostSheets the collection of Vouchers is deleted

推荐答案

这是表的结构:

关系

CostSheets
CSID (PK)
CSField2
CSField3

one ___
          | __many


代金券
VID (PK)
CSID (FK)
Field3



您需要使用ON UPDATE CASCADEON DELETE CASCADE命令来强制引用完整性.例如:
This is the structure of your tables:

RELATIONS

CostSheets
CSID (PK)
CSField2
CSField3

one___
         |__many


Vouchers
VID (PK)
CSID (FK)
Field3



You need to enforce referential integrity, using ON UPDATE CASCADE and ON DELETE CASCADE commands. For example:
ALTER TABLE History.ClientVersionMap ADD CONSTRAINT FK_ClientId_Version
FOREIGN KEY(ClientId, Version) REFERENCES Reports.ClientVersionMap(ClientId, Version)
ON DELETE CASCADE ON UPDATE CASCADE



更多信息:
更改表 [ table_constraint [删除级联和更新级联 [



More at:
ALTER TABLE[^]
table_constraint[^]
DELETE CASCADE and UPDATE CASCADE[^]


这篇关于更新表依赖于另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆