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.

closed as unclear what you're asking by Erik Darling, mustaccio, Vérace, hot2use, LowlyDBA Dec 11 '18 at 18:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 . . .

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