I have a stored procedure in SQL Server 2008 that needs to delete a few rows of data. But when I run it, it returns a fail and a value of -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
I can’t seem to find what’s wrong.
You’re able to check out the messages yourself, add this to your CATCH block:
You may want to change that SELECT to PRINT, and then you’ll be able to see the results in the ‘Messages’ tab when running the SP within SSMS.
I suspect it’s a problem with a Foreign Key or a possible trigger.