Re: [SQL] Deleting entries from multiple tables

2010-11-30 Thread manidegr8
yes i know about on delete cascade it automatically delete the child when master is deleted but the database i m working on is not built in this fashion tables r built on default rules so constraints r there i m jus asking to build a procedure or function that taking from the user and deletes th

Re: [SQL] Deleting entries from multiple tables

2010-11-30 Thread Achilleas Mantzios
Here is my take on how to regard parent tables in one-to-many FK relationships. If lets say we have a situation when we model e.g. mail messages and its attachments, then we might want to use ON DELETE CASCADE since there is absolutely no reason for an attachment to exist when the main message is

Re: [SQL] Deleting entries from multiple tables

2010-11-30 Thread Dusan Misic
To be precise, if you used defaults, you can't delete any row in table A that has rows referencing to it in tables B and C. On Tue, Nov 30, 2010 at 6:59 AM, manidegr8 wrote: > > i am trying to run a query but its not working may be due to constraint > conflicts > > i have table A, B and C > B an

Re: [SQL] Deleting entries from multiple tables

2010-11-30 Thread Dusan Misic
What is ON DELETE part of the foreign key constraint? If you set it to CASCADE, then your delete from the parent table will cascade to child tables (to put it simpler, when you delete record in table A, then PostgreSQL will delete any rows in tables B and C that are referencing original row (or co

[SQL] Deleting entries from multiple tables

2010-11-30 Thread manidegr8
i am trying to run a query but its not working may be due to constraint conflicts i have table A, B and C B and C have a foreign key linked with A's primary key so i want to delete an entry from A for that i hav to delete child records first can u design a query which wont conflict the constrai