如何执行两个更新语句

时间:2011-07-15 21:31:09

标签: asp.net sql stored-procedures

    ALTER PROCEDURE dbo.ModeratorSpamDeleteThread

  @ThreadsID INT

AS

  DELETE Threads
  WHERE ThreadsID=@ThreadsID

我有这个..但它告诉我,我不能删除表,因为它通过外键连接到另一个表..

所以我也需要这样做:

  @ThreadsID INT

AS

  DELETE Comments
  WHERE ThreadsID=@ThreadsID

问题是我如何将两个口音组合成一个?

2 个答案:

答案 0 :(得分:2)

首先在注释中执行删除,然后在线程中执行删除。

ALTER PROCEDURE dbo.ModeratorSpamDeleteThread
  @ThreadsID INT
AS

DELETE Comments
WHERE ThreadsID=@ThreadsID 

DELETE Threads
WHERE ThreadsID=@ThreadsID

答案 1 :(得分:1)

这是你可以做到的:

ALTER PROCEDURE dbo.ModeratorSpamDeleteThread
@ThreadsID INT
AS

  DELETE Comments
  WHERE ThreadsID=@ThreadsID

  DELETE Threads
  WHERE ThreadsID=@ThreadsID

GO