0
我試圖執行一個存儲過程,但我不確定如果我要走正確的方向。當我的IF條件爲真,也不會打印我raiseerrors ...SQL raisserror沒有顯示
set transaction isolation level repeatable read
declare @return_value int = 0
declare @someValue int = 3
SET @retry = 3;
--Keep trying to update
--table if this task is
--selected as the deadlock
--victim.
WHILE (@retry > 0)
BEGIN
BEGIN TRY
BEGIN TRANSACTION;
--check someValue
if @someValue < 5
begin
raiserror ('number is less than 5', 16,1)
ROLLBACK TRANSACTION
return 99
end
--all o.k , set retry 0 ending the while, commit transaction--
SET @retry = 0;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
RAISERROR ('Errors found, please fix these errors and retry. Transaction Rolled back', 16, 2);
-- Check error number.
-- If deadlock victim error,
-- then reduce retry count
-- for next update retry.
-- If some other error
-- occurred, then exit
-- retry WHILE loop.
IF (ERROR_NUMBER() = 1205)
SET @retry = @retry - 1;
ELSE
SET @retry = -1;
IF XACT_STATE() <> 0
ROLLBACK TRANSACTION;
END CATCH;
END; -- End WHILE loop.