Can you provide some example data to back this? AFAIK whether someone can see a schema/table/whatever is completely based upon security permissions and has nothing to do with the informational views. But seeing an example might help clarify things, especially if you're talking about a system schema.
return correct table_schema
There are 2 table schemas in the information_schema.columns table for a specific table. They're both base tables. None of the tables are listed as DENY in the sys.database_permissions. Only 1 of the table schemas are visible in SSMS. How do you determine from meta data which table schema is visible in SSMS with TSQL?
Developer technologies | Transact-SQL
4 answers
Sort by: Most helpful
-
-
Tom Phillips 17,781 Reputation points
2022-09-07T19:29:21.19+00:00 Normally SSMS displays all objects in the database.
Without your query or your results of the query, it is hard to guess as to your problem.
-
Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator2022-09-07T21:29:06.09+00:00 Rather than looking for DENY, look for GRANT. To be able to see a table, a user needs to hold at least the permission VIEW DEFINITION (which is implied if you have SELECT permission). This example illustrates:
CREATE TABLE T1 (a int NOT NULL) CREATE TABLE T2 (a int NOT NULL) CREATE USER UselUser WITHOUT LOGIN GRANT SELECT ON T1 TO UselUser go EXECUTE AS USER = 'UselUser' go select TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE from INFORMATION_SCHEMA.TABLES go REVERT go DROP TABLE T1, T2 DROP USER UselUser -
Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator2022-09-13T21:00:52.213+00:00 I'm not trying to figure out how to grant or deny access. I need to know how to determine table(s)' access level programmatically.
To see whether a user has permission to an object, you can do this:
EXECUTE AS USER = 'YourUser' go SELECT has_perms_by_name('dbo.YourTable', 'OBJECT', 'SELECT') go REVERTDetermining the permissions without impersonation can be very difficult, since permissions, both GRANT and DENY can come from many places.