Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a stored procedure as another user permission

Tags:

I faced the following problem: there's a user who has to execute a stored procedure (spTest). In spTest's body sp_trace_generateevent is called. sp_trace_generateevent requires alter trace permissions, and I don't want user to have it. So I would like user to be able to execute spTest. How can I do that?

like image 568
StuffHappens Avatar asked May 12 '10 13:05

StuffHappens


People also ask

How do I grant a stored procedure execution permission?

To grant permissions on a stored procedureExpand Stored Procedures, right-click the procedure to grant permissions on, and then select Properties. From Stored Procedure Properties, select the Permissions page. To grant permissions to a user, database role, or application role, select Search.

Which permission does a user need to run a stored procedure?

If you've READ permission on database, you can read data only from Tables, Views, and Functions. But to execute stored procedures, you need to provide permission explicitly to user.

Can Db_owner execute stored procedure?

Btw, db_owner is a database ROLE in SQL Server , not a permission. Or if you want the user to execute all current and future stored procedures and scalar-valued functions: grant execute on schema::dbo to User for a single schema, or just grant execute to User for the whole database.


2 Answers

Try this:

EXECUTE AS user = 'special_user'  EXECUTE YourProcerdure  REVERT 

see these:
Understanding Context Switching <<<has examples of things like you are trying to do
Understanding Execution Context
EXECUTE AS Clause (Transact-SQL)
EXECUTE AS (Transact-SQL)

like image 103
KM. Avatar answered Sep 18 '22 20:09

KM.


As others have suggested you can achieve what you wish using the Execute As clause. For examples of implementation choices take a look at the Books Online documentation for the Execute As clause.

For further reading and to develop more understanding of this topic, what you are looking to achieve comes under the security concept of Context Switching.

like image 43
John Sansom Avatar answered Sep 20 '22 20:09

John Sansom