Deleting records in a master detail relation

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Cogito
Posts: 24
Joined: Sat 05 Jul 2008 07:15

Deleting records in a master detail relation

Post by Cogito » Mon 14 Jul 2008 08:12

Hi,

if I delete a record in a master table, the detail records are not automatically deleted, because a foreign key restriction. Is it possible to implement here a cascaded delete?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 15 Jul 2008 06:11

There are two ways to implement this. The first way is to define the foreign key in the table with the ON DELETE CASCADE option. The second one is to delete correspondent records in the detail table in the BeforeDelete event handler of the master dataset.

Post Reply