我的腳本被封裝在開始事務和提交事務中。 我甚至不能使用Go inbetween。 在我想禁用一個觸發器,然後腳本要創建另一個 但是,當我同時執行兩個語句,我得到了FOLL錯誤:'CREATE TRIGGER'必須是查詢批次中的第一條語句
Msg 111, Level 15, State 1, Line 6 'CREATE TRIGGER' must be the first statement in a query batch.
我的代碼是:
BEGIN TRY
BEGIN TRANSACTION
DISABLE TRIGGER [dbo].[trg_Beneficiary_After_Update] ON [dbo].[Beneficiary]
CREATE TRIGGER [dbo].[trg_Beneficiary_After_Update1] ON [dbo].[Beneficiary] FOR UPDATE AS
BEGIN
INSERT INTO [dbo].[Beneficiary_History]([Beneficiary_Id],[Customer_Id],[Beneficiary_Type],[Nick_Name],[Rib_Key],[Action_Flag],[Benef_No],[Original_Date],[Provider_Id],[Create_Date])
SELECT [Beneficiary_Id],[Customer_Id],[Beneficiary_Type],[Nick_Name],[Rib_Key],'U',[Benef_No],[Create_Date],[Provider_Id],GETDATE() FROM DELETE
PRINT 'AFTER Beneficiary Table UPDATE1 trigger fired.'
END
UPDATE [dbo].[Beneficiary] SET [Benef_No] = REPLACE (Benef_No, +2120, ++212) WHERE Benef_No like '+2120%'
DISABLE TRIGGER [dbo].[trg_Beneficiary_After_Update1] ON [$(oltpdb)].[dbo].[Beneficiary] ;
ENABLE TRIGGER [dbo].[trg_Beneficiary_After_Update] ON [$(oltpdb)].[dbo].[Beneficiary]
end
COMMIT TRANSACTION END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH;
需要看到代碼... – VDK
簡單地切換順序? – jarlh
我無法在此發佈代碼。 – Priyanka