Reputation: 2499
I have a stored procedure Which we call it Test
here.
For simplicity I modified the SP code to:
Select * from table A
I can run this SP without any issues.
Now if I use Dynamic SQL
@SQL='Select * from table A'
EXECUTE (@SQL)
I get
The SELECT permission was denied on the object 'A', database 'MyDb', schema 'dbo'.
What is different here?
Upvotes: 0
Views: 61
Reputation: 69564
Dynamic SQL has this restriction/limitation. When you use dynamic sql inside a stored procedure , even if the calling user has the permissions on the stored procedure , the user also need permissions on the tables/objects being called inside the dynamic sql .
You have two options
Upvotes: 4