简体   繁体   中英

How can I make selecting from a view trigger an agent job?

I'm open to any dirty trick here, no matter how unclean or ill-advised they are.

My users query my server via Excel. I wish for the users to be able to trigger an agent job from Excel. They only have the 'SELECT' and 'View Definitions' permission. To the best of my awareness, this means that I must devise some method by which my users can trigger an agent job via querying a view. How can this be done?

You could set up an SQL job that monitors (runs every X minutes?) query history: How to see query history in SQL Server Management Studio and as soon as it finds the query on the view - it writes down the execution timestamp and triggers the job you want to run. Next run it looks for the same query but triggered after the saved timestamp.

This would be more "safe" if you have a proper monitoring tool already running on the server.

But you should really consider a better solution for this.

EDIT: Based on your comments - create a stored procedure that triggers the job. Grant your users execution rights on the stored procedure. Inside the procedure use context switching to be able to run the job without giving the users rights to run any job - just switch to a service account: https://learn.microsoft.com/en-us/sql/t-sql/statements/execute-as-transact-sql?view=sql-server-ver15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM