0

I need to make a trigger about who and when created a view. I have some groundwork about it.Code. So, when some user is running a script for create view, trigger is crushing because this user doesn't have a permission to insert. Execute as When I use trigger with EXECUTE AS OWNER, there is a problem with it. Problem - OWNER is not a valid parameter for EXECUTE AS in the context of server and database level triggers.

  • 1
    EXECUTE AS OWNER is not applicable here because database-level triggers don't have an owner (this is related to why you can't create a database-level trigger in the scope of a specific schema). – Aaron Bertrand Dec 8 '18 at 5:24
4

Use execute as self

create or alter trigger check_view 
on database
with execute as self
for create_view
as . . .

or execute as 'dbo'

create or alter trigger check_view 
on database
with execute as 'dbo'
for create_view
as . . .
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.