return correct table_schema

J Oakland 21 Reputation points
2022-09-07T17:08:29.173+00:00

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
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 61,106 Reputation points
    2022-09-07T18:00:38.557+00:00

    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.

    0 comments No comments

  2. 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.


  3. Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator
    2022-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  
    

  4. Erland Sommarskog 128.9K Reputation points MVP Volunteer Moderator
    2022-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  
       REVERT  
    

    Determining the permissions without impersonation can be very difficult, since permissions, both GRANT and DENY can come from many places.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.