Sql-server – Hide schemas from users in MSSQL

azure-sql-databasedatabase-designsql server

I'm creating a database with a few different schemas.

99% of users connect using Excel, and when they do they see all the system stuff:

enter image description here

This just confuses the users and I would like to configure SQL Server so that they only see UK_data and UK_reports.

So far I tried denying select on the things that I want to hide and only allowing select on the UK_ schemas, but it didn't work.

Is there a way to hide them from users?

Thanks!

Best Answer

I maybe found two solution for you:

  1. HIDE

Hide Table "Person.Address"

EXEC sp_addextendedproperty
@name = N'microsoft_database_tools_support',
@value = 'Hide',
@level0type = N'Schema', @level0name = 'Person',
@level1type = N'Table', @level1name = 'Address';
GO

Show Table "Person.Address"

EXEC sp_dropextendedproperty
@name = N'microsoft_database_tools_support',
@level0type = N'Schema', @level0name = 'Person',
@level1type = N'Table', @level1name = 'Address';
GO
  1. DENY
`DENY VIEW DEFINITION ON Schema.Table TO UserName;`

Now UserName won’t be abe to see Table in Object Explorer. In Fact, they won’t be able to see the table in sys.tables or INFORMATION_SCHEMA.TABLES.

You can Use the DENY keyword to deny certain Users and REVOKE to Remove the existing permission.