Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i have to delete multiple(two or three) table data rows with one query statement in sqlcommandquery with where condition. is it possible? if possible then how can we do it?

thanks in advance
Posted

Better to write a Stored Procedure, that accepts your all conditions
and execute your delete statements one by one or using transaction way.
 
Share this answer
 
You have to write a delete statement for each Table. I believe it's not possible to delete from three tables using only one Where statement, unless there is a relationship between these tables allowing a Cascade Delete.
 
Share this answer
 
Comments
mkcm2011 11-Nov-11 4:28am    
how to do it....i want to delete two table rows with where statement , where id is same ......they are in relationship like one have details of college student name age and all with id and other have their subjects marks with id. plz help me out
UJimbo 11-Nov-11 4:38am    
http://www.dbasupport.com/forums/showthread.php?t=11441
It also explains how to setup two tables for a cascade delete, which means deleting the row in one table will also delete the row in the second table automatically.
Dear Friend,

Use StoredProcedure and Implement all methods What ever you Required if yo want to Delete total Data in Table use Truncate.


Regards,

Anilkumar.D
 
Share this answer
 
Comments
mkcm2011 11-Nov-11 4:29am    
thanks but how to do it...i want proper code
you need to write a store procedure for all deletes and need to pass all the parameters....it will work..
 
Share this answer
 
Yes you can, just supply the where filter :
SQL
DELETE FROM [tablename] where column1=9 or column2>2
 
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