2012-04-01 168 views
0

我想用DELETE做與SELECT一樣的事情。我無法弄清楚連接如何與刪除工作?在存儲過程中刪除SQL Server

SELECT * 
FROM table1 1 inner join table2 2 
on 1.Id= 2.Id inner join table3 3 
on 3.id=2.Id 
WHERE 3.id= @Id 

回答

2

這應該工作:

DELETE table1 
FROM table1 t1 
INNER JOIN table2 t2 
on t1.Id= t2.Id 
INNER JOIN table3 t3 
on t2.Id= t3.Id 
WHERE [email protected] 
+0

它不工作,沒有什麼是越來越刪除。所有表都連接到table2,並且我有刪除規則級聯。 – 2012-04-01 22:25:44

+0

你有給定ID的table1,table2和table3的記錄嗎? – 2012-04-01 22:29:54

+0

謝謝!我的電腦一時心情不好,答案很好! – 2012-04-01 22:45:14

1
DELETE table1 
FROM table1 t1 inner join table2 t2 
on t1.Id= t2.Id inner join table3 t3 
on t3.id=t2.Id 
WHERE t3.id= @Id