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

问题描述

我有表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

推荐答案

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[^]


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

06-30 12:25