I have folders table and docs table and folders_docs table that maps each doc to one folder. So I try to delete some row from folder table but of course it gives an error like:” Cannot delete or update a parent row: a foreign key constraint fails “
How can cope with that problem?
Thanks in advance…
You can improve the use of REFERENTIAL INTEGRITY in which you define constraints (foreign keys) and propagate the folders deletion to folders_docs and then to docs, but in your case you must play attention at your design: you have a N:M relation between folders and docs, so with a folder deletion you should stop the propagation at the folders_docs table, otherwise you won’t be able to find docs in other folders if referenced.
What SQL product are you using?
In many SQL products (SQL Server for example) you can add the ON DELETE CASCADE clause to the ADD CONSTRAINT part of the ALTER TABLE DDL to accomplish this.