Please post the DDL for your tables (CREATE TABLE statements) along with some sample data and expected results. Anyway, the following is an example approach:CREATE TABLE #a(a INT NOT NULL PRIMARY KEY, z VARCHAR(10) NOT NULL)CREATE TABLE #b(b INT NOT NULL PRIMARY KEY, a INT NOT NULL)CREATE TABLE #c(c INT NOT NULL PRIMARY KEY, b INT NOT NULL)INSERT #a VALUES(1,'Fred')INSERT #a VALUES(2,'Barney')INSERT #a VALUES(3,'Mr. Slate')INSERT #b VALUES(100,2)INSERT #b VALUES(200,2)INSERT #b VALUES(300,1)INSERT #b VALUES(400,3)INSERT #c VALUES(10,200)INSERT #c VALUES(20,300)INSERT #c VALUES(30,100)INSERT #c VALUES(40,400)SELECT * FROM #a a INNER JOIN #b b ON a.a=b.aINNER JOIN #c c ON b.b=c.b-- delete where z=BarneySELECT b.a, b.b INTO #DELETEFROM #a a INNER JOIN #b b ON a.a=b.aINNER JOIN #c c ON b.b=c.bWHERE a.z='Barney'DELETE cFROM #c cINNER JOIN #DELETE d ON c.b=d.bDELETE bFROM #b bINNER JOIN #DELETE d ON b.b=d.bSELECT * FROM #a a INNER JOIN #b b ON a.a=b.aINNER JOIN #c c ON b.b=c.bDROP TABLE #a, #b, #c, #DELETE
You have to perform 2 separate DELETE statements. You'd copy the key columns you'd need for each table you want to DELETE into a separate table, so that you don't lose that data after the first DELETE statement.