patternsqlModerate
Alter disabled trigger in SQL Server without enabling it
Viewed 0 times
withouttriggersqldisabledserveralterenabling
Problem
It seems like triggers get enabled automatically after altering them. How can I alter triggers programmatically without changing their enabled/disabled status?
Code to reproduce:
Code to reproduce:
create trigger trig
on MyTable
after insert
as select 0
go
disable trigger trig on MyTable
go
select is_disabled from sys.triggers where name = 'trig'
go
alter trigger trig
on MyTable
after insert
as select 1
go
select is_disabled from sys.triggers where name = 'trig'Solution
You can't. You just need to disable it again. There is no
The disable trigger topic explicitly calls out that
Changing the trigger by using the ALTER TRIGGER statement enables the
trigger.
ALTER TRIGGER syntax that prevents this.The disable trigger topic explicitly calls out that
Changing the trigger by using the ALTER TRIGGER statement enables the
trigger.
Context
StackExchange Database Administrators Q#159022, answer score: 10
Revisions (0)
No revisions yet.