Link to home
Start Free TrialLog in
Avatar of osca
osca

asked on

Cascade Deletion - Store Procedure

We have tried implementing cascade deletion store procedures for referenced table(Primary key) and its referencing tables (Foreign key). But it was not successful. Since, the records in the referencing tables must be deleted first before those in the referenced table. Could someone provide some advices.
ASKER CERTIFIED SOLUTION
Avatar of Victor Spiridonov
Victor Spiridonov
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of osca
osca

ASKER

We did try this method, but it didn't work. The error was due to the presence of foreign key in the referencing tables, therefore the 'deleted' 'tmp table' cannot be created in the first place, i.e. no deletion on the referenced table (with primary key) can be performed, until all the records in the referencing tables are removed.
You can't have both. You either use REFERENCES constraint or do all referencial integrity enforcement by using triggers: you have to create INSERT, DELETE and UPDATE triggers instead of REFERENCSES. Or  you can implement it in your application. In this case all delete operations should be done only through your application