Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Management Studio connection defaults to 'master' when selecting a database-specific object

Tags:

In SQL Server 2008 R2 Management Studio, if I right-click on an object inside a specific database and choose "Select top 1000 rows ..", the database connection for the query window always opens on 'master' while the table name is fully qualified as [database].[dbo].[table]. This makes it impossible to jump in and tweak out this query and insert joins, etc., to the statement without also fully-qualifying everything I add, or add a USE statement, or select the database from the drop-down menu.

Is there a setting or something that will make query windows open with a database connection of the selected object browser's database rather than connect to 'master', and not fully qualify the object's database in the query text? I realize that I can register my SQL connection to default to my database, but we actually go through multiple new databases every week--in a given month I will have touched tens of databases--so it would be difficult to manage multiple database registrations. I would rather it if SSMS just connected to the specified database. Possible and straightforward?

like image 855
Jon Davis Avatar asked Aug 16 '11 01:08

Jon Davis


People also ask

How do I change connection properties in SSMS?

In SQL Server Configuration Manager, select SQL Server Services. In the details pane, right-click SQL Server (<instancename>), and then select Properties. In the SQL Server (<instancename>) Properties dialog box, change the server properties on the Service tab or the Advanced tab, and then select OK.

How do I connect to a specific database?

To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.

How do I connect to a single database in SQL Server?

In SSMS, edit the properties of your login (under security > logins) and on the "general" tab there is a "default database" drop down. It is probably set to master, you can set it to the database you want used by default on your next connection.


Video Answer


1 Answers

If you are going in via Win Auth, are in a group, are using SA or some other userid, or are in a situation where changing your login is not really the solution, AND if all you wish to do is default to a database in the query editor:

  • In an existing open query editor, right-click, select Connection, Change Connection.

  • Click the Options button to expand the options.

  • In the Connection Properties tab, select the database you wish to connect to.

SSMS will remember your selection for that server. You may have to repeat for other servers, but it does remedy having a default database other than master.

like image 197
TulsaDavid Avatar answered Sep 27 '22 22:09

TulsaDavid