0

我在 SQL Server 2008 中有一个存储过程,需要删除几行数据。但是当我运行它时,它返回一个失败和一个值-6。

ALTER procedure [dbo].[p_CaseFiles_Exhibits_DeleteExhibits]
  @ExhibitID int
, @Message nvarchar(50) output
as
declare @FileID int
set @FileID = (select FileID from CaseFileExhibits where ExhibitID = @ExhibitID)
begin transaction
  begin try
    delete from CaseFileExhibitMovementTracking where ExhibitID = @ExhibitID
    delete from CaseFileExhibitAttachments where CaseFileExhibitID = @ExhibitID
    delete from CaseFileExhibits where ExhibitID = @ExhibitID
    delete from CaseFileExhibitPropertyLink where ExhibitID = @ExhibitID
    update CaseFileQuickStats set ExhibitCount = ExhibitCount -1 where CaseFileID = @FileID    
    commit transaction
  end try
  begin catch
    set @Message='Fail'
    rollback transaction
  end catch

我似乎无法找到问题所在。

4

1 回答 1

3

您可以自己查看消息,将其添加到您的 CATCH 块中:

SELECT
ERROR_NUMBER() AS ErrorNumber
        ,ERROR_SEVERITY() AS ErrorSeverity
        ,ERROR_STATE() AS ErrorState
        ,ERROR_PROCEDURE() AS ErrorProcedure
        ,ERROR_LINE() AS ErrorLine
        ,ERROR_MESSAGE() AS ErrorMessage;

您可能希望将该 SELECT 更改为 PRINT,然后在 SSMS 中运行 SP 时,您将能够在“消息”选项卡中看到结果。

我怀疑这是外键的问题或可能的触发器。

于 2012-09-26T15:44:44.133 回答