我有一个 SQL 脚本,已设置为发布生产环境。我将不同的项目封装到不同的事务中。在每个事务中,我们创建了存储过程。我得到了错误消息:
Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'procedure'.
我创建了这个示例脚本以说明问题。
Begin Try
Begin Transaction
-- do a bunch of add/alter tables here
-- do a bunch of data manipulation/population here
-- create a stored proc
create procedure dbo.test
as
begin
select * from some_table
end
Commit
End Try
Begin Catch
Rollback
Declare @Msg nvarchar(max)
Select @Msg=Error_Message();
RaisError('Error Occured: %s', 20, 101,@Msg) With Log;
End Catch
这个错误似乎意味着我不能在事务中创建存储过程,但我没有找到任何文档表明相反的情况(也许今天谷歌不友好)。