在存储过程SQL Server中删除

时间:2012-04-01 22:07:25

标签: sql-server stored-procedures

我想用DELETE做同样的事情,就像使用SELECT一样。我无法弄清楚联接如何与删除一起工作?

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 个答案:

答案 0 :(得分: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 t3.ID=@ID

答案 1 :(得分: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