This is the structure of your tables:
RELATIONS |
---|
CostSheets | CSID (PK) | CSField2 | CSField3 |
|
|
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
More at:
ALTER TABLE[
^]
table_constraint[
^]
DELETE CASCADE and UPDATE CASCADE[
^]