开发者

TSQL query to verify permissions and object exists

开发者 https://www.devze.com 2023-01-08 02:58 出处:网络
I am writing a query that will return if a table or stored proc exists within a database if a particular role has been assignned execute permissions to execute that particular stored proc.

I am writing a query that will return

  1. if a table or stored proc exists within a database
  2. if a particular role has been assignned execute permissions to execute that particular stored proc.

I guess I need to query the master database and wiggle thru that to get to the database and the table or stored proc that I am looking for. How can I get a 'true / false' if execute permissions have been assigned to a particular role on that object开发者_如何学运维?


USE YourDatabase

/*To find out if it exists*/

SELECT OBJECT_ID('dbo.spFoo') /*Will be NULL if it doesn't exist or you don't have 
                                permission to see the object*/

/*To find out the permissions on it take a look at the following system views*/

select * from sys.database_permissions p
inner   JOIN sys.database_principals dp
   on     p.grantee_principal_id = dp.principal_id
   where major_id=object_id('dbo.spFoo')
0

精彩评论

暂无评论...
验证码 换一张
取 消