Click here to Skip to main content
15,910,797 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted

1 solution

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:
SQL
ALTER TABLE History.ClientVersionMap ADD CONSTRAINT FK_ClientId_Version
FOREIGN KEY(ClientId, Version) REFERENCES Reports.ClientVersionMap(ClientId, Version)
ON DELETE CASCADE ON UPDATE CASCADE


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900