How to find if the logged in User has permissions to see "view" definitions on SQL Server? I need to find out what tables/columns a view is made from,
I used this SQL for the same; for view definition, we used this query:
Query:
select *
from sys.objects
where name like '%SECTION_MASTER_V%'
Result: 579337674
Query:
SELECT definition
FROM sys.objects o
JOIN sys.sql_modules m ON m.object_id = o.object_id
WHERE o.object_id = 579337674
AND o.type = 'V'
Result: null
I get null as a result. Does anyone knows what may be wrong here?
3条答案
按热度按时间7vux5j2d1#
You can see object-level permissions using this query: the commented-out section in the
WHERE
clause will limit the results to theVIEW DEFINITION
permission.5lwkijsr2#
I get null as a result. Does anyone knows what may be wrong here?
You need the
VIEW DEFINITION
permission, otherwise you get an empty result set.Use can use
sys.fn_my_permissions
orHAS_PERMS_BY_NAME
to get the relevant permission on a database for the current user:HAS_PERMS_BY_NAME:
You get a simple
0
or1
as a result of this query.sys.fn_my_permissions
The result set for this query looks like this:
With impersonation
If you have the
IMPERSONATE
permission, you can even check it for another user:or
wbgh16ku3#
Two things: