I come from Oracle Database and now I am trying learn SQL Server and I don't undestand why may I viewer others databases, like the master for example, with a common user without privileges in this database?


You mean that you can see that the database exist, even if you don't have access to it? Yes, that is the way it is, quite simply.

From a technical standpoint, the reason is (likely) that whether or not you have access to a database is stored inside the database. So, SQL server would have to open all databases in tools such as SSMS/Object Explorer in order to determine whether or not to show each database. I.e., the info isn't stored in master.

From a practical standpoint, the reason is it is because MS did it that way. I'm not trying to be a smart-Alec here, but some things are just the way they are...

Two ways with which you can possibly handle this:

Use contained databases. If you turn on partial containment for a database, then you can login directly to the database without a login. The session will be sandboxed to that database.

Deny the VIEW ANY DATABASE server permission for the logins in question. They will now only see the databases that they own. I.e., this is only usable for persons who own the databases they will use. A non-owner will still be able to use the database it has access to, but it won't show up in sys.databases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.