2

Is there a way to set the 'available databases' in the dropdownbox of SQL Server 2012 toolbar to a default database that you are using?

I know you can use the following in the query:

USE databasename
GO

or

just select the right database in the dropdownbox,

and all will be well, but sometimes if I want to run a quick query and skip(forget) those steps it refers to the 'master' and the query fails.

Is there a way?

Inus C
  • 1,521
  • 1
  • 16
  • 23
  • 1
    You can set a [default database](http://msdn.microsoft.com/en-us/library/ms189828.aspx) for your login, is that what you need? – Pondlife Apr 04 '13 at 15:37
  • If I had to guess it would be this, but not sure how to use it: DEFAULT_DATABASE =database – Inus C Apr 04 '13 at 15:52
  • 1
    The documentation doesn't show an example of setting the default database, but it does show examples of setting other options so it should be obvious how to set the default database. Just try doing it and you'll probably work it out within a few seconds. – Pondlife Apr 04 '13 at 15:56
  • A little searching gets you there tx – Inus C Apr 04 '13 at 16:07
  • Exec sp_defaultdb @loginame='login', @defdb='database' as seen on :http://stackoverflow.com/questions/362434/how-can-i-change-my-default-database-in-sql-server-without-using-ms-sql-server-m – Inus C Apr 04 '13 at 16:10

2 Answers2

3

Have you looked at your users's default database ? in SQL Server's users, you can set your user default database.

In SSMS once you are connected to the server:

  • Under Security/Logins you should see your User or Windows groups
  • Right click on the User and select properties.
  • Under the General page select your default database (see image below):
  • Click Save

enter image description here

codea
  • 1,439
  • 1
  • 17
  • 31
0

If you expand the databases section in object explorer, select the one you want to query and then click the New Query button, it will automatically set the database to the one that you selected.

However, if you right click an object in object explorer and do a select top 1000 etc, it will automatically use the master database and refer back to the database you are using via the 3 part name, which can be a bit irritating.

steoleary
  • 8,968
  • 2
  • 33
  • 47