我有下面的T-SQL:語法錯誤與TRY內DROP CONSTRAINT/CATCH
USE [MYDB]
GO
SET XACT_ABORT, NOCOUNT ON
GO
BEGIN TRANSACTION;
BEGIN TRY
ALTER TABLE [dbo].[ContactRole]
DROP CONSTRAINT [FK_8bff7074914bc29885004c0a323]
GO
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber ,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState ,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine ,ERROR_MESSAGE() AS ErrorMessage;
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
END CATCH
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
解析的時候,給了我這個錯誤:
消息102,15級,狀態1,第9行
「FK_8bff7074914bc29885004c0a323」附近的語法不正確。
當單獨或者只在一個事務中,沒有解析錯誤。