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 に答える