Avatar of mssql_v2005
mssql_v2005
 asked on

SQL query+SQL Server

I want to delete rows from 3 tables based on ID column. Can you please share logic/or query to delete rows.

ex: 3 tables with the name of A,B,C

ID column exist on all 3 tables. I will pass ID as input parameter and want to delete rows from 3 tables from single query.
Microsoft SQL ServerDatabasesMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Lokesh B R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mssql_v2005

ASKER
I don;t want SP, can you share without SP
Vitor Montalvão

The DELETE command only accepts a table or a view name so I don't think you can't do it from a single statement.
MohitPandit

If you want to achieve with your single query then you need to CREATE FOREIGN KEY with ON DELETE CASCADE

Best Regards
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
mssql_v2005

ASKER
This solution is working partially for me.
Vitor Montalvão

I think you were too fast to accept a solution.
Are the tables related? A delete trigger is an acceptable solution for you?