简体   繁体   中英

SQL Server Management Studio, Beginner

So, I have this question: Use the following query to determine the principle_id values for suzie and jimmy.

 select *
 from sys.database_principals
 where name in ('suzie','jimmy')

Using the principle_id values obtained from the query above; write a SELECT query using the sys.database_permissions table that lists ALL permissions that have been granted to suzie and jimmy.

Principal id's I got were "5 & 6"

Then I used:

SELECT*
FROM sys.database_permissions
WHERE grantee_principal_id in ('5','6')

Now the question is we're asked now to use the OBJECT_NAME function in your query to show the view names instead of just their major_id values. I don't quite understand how to use the OBJECT_NAME function, I have been playing around and can't get it. Any hints or help would be greatly appreciated. Thanks!

Are you looking for something like this?

grator_principal_id will return all objects where these principal gave the grant and grantee_Prinicipal_id return all objects where Suzie and Jimmy were granted Details here

SELECT *
     ,OBJECT_NAME(major_id) AS TheObject
FROM sys.database_permissions
WHERE grantor_principal_id in (select principal_id
                               from sys.database_principals
                               where name in ('suzie','jimmy'))

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