Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can we delete data from multiple tables using a single query.


Thanks in advance.
Posted

The best way if to use Cascaded Deletes[^], so that the database will always handle it for you.

Alternatively, I would suggest that using transactions might be a better alternative, possibly inside a stored procedure.
 
Share this answer
 
Comments
Uday P.Singh 12-Jul-11 4:07am    
good answer my 5!
If the tables are related (i.e., they have a common key), you can use ON DELETE CASCADE clause in the foreign key specification. Deleting rows from a master table will result in the deletion of all related child rows from the dependant tables.

If the tables are not related, you must use multiple DELETE statements.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900