我知道有很多问题在问这个问题,但我不明白为什么这段代码会失败,但启动存储过程的“BEGIN”表示它期待“EXTERNAL”,这没有意义。
IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Insert_ToTable'))
BEGIN
CREATE PROCEDURE [dbo].[Insert_ToTable]
AS
BEGIN
BEGIN TRANSACTION
BEGIN TRY
//Stored Procedure Code
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
END
END