使用回滚事务创建过程时出错 [英] Error in creating procedure with roll back transaction
问题描述
大家好,
我正在尝试创建一个回滚事务来创建一个SP,在我使用的sql查询下面。
当我执行时发出轰鸣声错误
消息156,等级15,状态1,行5
关键字'proc'附近的语法不正确。
消息156,级别15,状态1,行31
关键字附近的语法不正确'proc'。
请纠正我。如果有人能很快给我答案,那就太好了。
在此先感谢...
begin tran cproc
开始尝试
创建proc samplep(
@fileid int)
as
start
end
结束尝试
开始捕获
IF @@ ERROR<> 0
BEGIN
PRINT'发现错误...回滚'
ROLLBACK TRANSACTION cproc
返回
END
ELSE
开始
打印'否错误...提交更改'
COMMIT TRANSACTION proc
end
结束捕获
我想你不能使用Try Catch块创建存储过程
查询中有太多错误。我已经更新了语法。
创建 proc samplep(
@ fileid int )
as
begin
begin tran cproc
开始尝试
print ' some logic'
end 尝试
开始 catch
IF @@ ERROR <> 0
BEGIN
PRINT ' 发现错误...回滚'
ROLLBACK TRANSACTION cproc
RETURN
END
ELSE
开始
PRINT ' 无错误...提交更改'
COMMIT TRANSACTION cproc
end
end catch
end
Hi All,
I am trying to create a roll back transaction for creating a SP, below the sql query i used.
When i execute am getting bellow error
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'proc'.
Msg 156, Level 15, State 1, Line 31
Incorrect syntax near the keyword 'proc'.
Please Correct me. It would be great if any one provide me the answer very soon.
Thanks in Advance...
begin tran cproc
begin try
create proc samplep(
@fileid int)
as
begin
end
end try
begin catch
IF @@ERROR <> 0
BEGIN
PRINT 'Errors Found ... Rolling back'
ROLLBACK TRANSACTION cproc
RETURN
END
ELSE
begin
PRINT 'No Errors ... Committing changes'
COMMIT TRANSACTION proc
end
end catch
I think you can't use Try Catch block for creating stored procedure
There are too many errors in you query. I have updated the syntax.
create proc samplep( @fileid int) as begin begin tran cproc begin try print 'some logic' end try begin catch IF @@ERROR <> 0 BEGIN PRINT 'Errors Found ... Rolling back' ROLLBACK TRANSACTION cproc RETURN END ELSE begin PRINT 'No Errors ... Committing changes' COMMIT TRANSACTION cproc end end catch end
这篇关于使用回滚事务创建过程时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!