My script is wrapped in a begin transaction and commit transaction. I cant even use Go inbetween. In the script I want to disable one trigger and then want to Create another one But when i execute both the statements simultaneously I get the foll error:
Msg 111, Level 15, State 1, Line 6 'CREATE TRIGGER' must be the first statement in a query batch.
My code is:
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;