Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
How can we delete data from multiple tables using a single query.
 

Thanks in advance.
Posted 11-Jul-11 22:24pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
Uday P.Singh at 12-Jul-11 4:07am
   
good answer my 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 7,373
1 OriginalGriff 5,571
2 Peter Leow 4,097
3 CHill60 2,858
4 Mika Wendelius 2,850


Advertise | Privacy | Mobile
Web02 | 2.8.150224.1 | Last Updated 14 Jul 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100