HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlModerate

Users cannot view tables in non-default schema in SSMS

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cannottablesssmsnonviewdefaultusersschema

Problem

I'm having an issue setting the VIEW DEFINITION permission appropriately at the schema level for one of my users. I've created the schema TestSchema and added some tables. The user currently has permissions set to access & modify the table (SELECT, UPDATE, DELETE, etc) through the dbo_datareader and dbo_datawriter roles. However, they cannot see any of the tables in the SSMS object explorer.

I've tried granting permissions to view definitions:

grant view definition on SCHEMA :: [TestSchema] to [User]


That didn't work. I tried setting the table-level permission:

grant view definition on [TestSchema].[NewTable] to [User]


That also didn't work. Then I tried just a blanket grant:

grant view definition to [User]


And that did work; they can now see TestSchema, as well as other schemas that they shouldn't have access to.

My goal here is to allow the user to view all tables within a given schema. How do I accomplish that? If I should be able to do this by default, what permissions should I be looking at to find why I can't?

Solution

Short answer: Don't use db_datareader or db_datawriter or their deny equivalents. They are for backwards compatibility only. Using them will cause issues like the one you are facing.

If you want to give principal Alice the SELECT, INSERT, UPDATE and DELETE permissions to all table-valued objects in schema Sales then use the following.

GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::Sales TO Alice ;


If you want to give principal Alice the SELECT, INSERT, UPDATE and DELETE permissions to all table-valued objects in all schemas then use the following.

GRANT SELECT, INSERT, UPDATE, DELETE TO Alice ;


Metadata visibility will then work correctly.

Code Snippets

GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::Sales TO Alice ;
GRANT SELECT, INSERT, UPDATE, DELETE TO Alice ;

Context

StackExchange Database Administrators Q#27525, answer score: 13

Revisions (0)

No revisions yet.