我收到錯誤「ROLLBACK TRANSACTION請求沒有對應的BEGIN TRANSACTION」。如果任何刪除語句的行數爲零,我試圖回滾事務。以下是我的代碼。我究竟做錯了什麼?請幫助ROLLBACK TRANSACTION請求在sql server中沒有對應的BEGIN TRANSACTION錯誤
alter procedure delete_staff(@staffID varchar(10))
as
declare @tempvar varchar(50), @staffName varchar(50), @jobTitle varchar(50), @dept varchar(50)
begin transaction trans1
declare @rc1 int
declare @rc2 int
declare @rc3 int
select @tempvar = left(@staffID,1) from Staff
delete from staff where staffID = @staffID
set @[email protected]@rowcount
delete from Login where userID = @staffID
set @[email protected]@rowcount
begin
if(@tempvar='S')
begin
delete from Specialist where specialistID = @staffID
set @[email protected]@rowcount
end
else if(@tempvar='H')
begin
delete from Helpdesk_Operator where helpdesk_OperatorID = @staffID
set @[email protected]@rowcount
end
commit transaction trans1
end
if(@rc1=0 or @rc2=0 or @rc3=0)
begin
rollback transaction trans1
end
爲什麼downvote?如果你不解釋你認爲是錯誤的,它不能改善答案。 – Guffa