Are you’re trying to drop a logon trigger in SQL Server, but you’re getting an error like the following?
“Cannot drop the trigger ‘trigger_name’, because it does not exist or you do not have permission.”
It could be because you’re missing the ON ALL SERVER
argument.
When you create a logon trigger, you use the ON ALL SERVER
argument.
You can also use this argument with DDL triggers. This argument applies the scope of the trigger to the current server.
When you drop such triggers (i.e. logon triggers, and DDL triggers that were created with ON ALL SERVER
), you must also use ON ALL SERVER
.
Example of the Error
I recently made this mistake myself. In my case, I was trying to drop a logon trigger like this:
DROP TRIGGER trg_limit_concurrent_sessions;
But that resulted in the following error:
Cannot drop the trigger 'trg_limit_concurrent_sessions', because it does not exist or you do not have permission.
I was confused, because I was the one who created the trigger. In fact, I’d created it earlier in the same session!
But then I realised my mistake.
The Solution
The solution was easy – simply append ON ALL SERVER
to my code.
DROP TRIGGER trg_limit_concurrent_sessions ON ALL SERVER;
Result:
Commands completed successfully.
I hope this article has helped if you’ve encountered the same error.