Only show databases to user in which he has db_owner rights

sourav dutta 211 Reputation points
2024-04-05T10:55:04.1366667+00:00

Hello,

Is there still no way for a user to only see their own database in SSMS.

I also tried edit the MS SQL role called "Public". Set the property "View any database" to "Deny". Then no databases are showing.

Thanks in Advance.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,743 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 101.1K Reputation points MVP
    2024-04-05T21:04:48.07+00:00

    If you deny or revoke VIEW ANY DATABASE, users will only be able to see the system databases and databases they own. But if they have access to a database, they will not see it, even if they are db_owner in the database. They can still use "USE db", and once they have done that, the database will display.

    Yes, this is a long-standing request that Microsoft has yet to come up with a solution to. (It is not entirely easy, because to check if a user has access to a database, you need to look in that database. May seem a like a slim thing, but on a server with 1000 databases all in auto-close, this is not fun at all.)

    0 comments No comments

  2. MikeyQiao-MSFT 560 Reputation points Microsoft Vendor
    2024-04-08T10:14:39.62+00:00

    Hi,sourav dutta

    I also tried edit the MS SQL role called "Public". Set the property "View any database" to "Deny". Then no databases are showing.

    After doing that ,Run this in a role of sysadmin:

    Use [WH_R]//The database
    GO
    EXEC dbo.sp_changedbowner N'user'//The username
    
    0 comments No comments