ILT – How To Change SQL Server Default Database?


I have been annoyed by having to change the database from the available databases drop-down whenever I want to write a query. This was because the default database which is always selected was the “Master” database which I never use.

SQL Server – Available Databases Drop Down Box







If you had the same problem then this is the solution you’ve been waiting for!

It’s really easy simple type following command and run it!

Exec sp_defaultdb @loginame='login', @defdb='master'

Replace ‘login’ and ‘master’ with your login (user) name and the name of the database you prefer to have as default.

Following is my exmple:

Exec sp_defaultdb @loginame='menol', @defdb='rp2_test'

From now on whenever you open a new query window, the default database will be the database you selected!

(You will need to log-back in to see the change working.)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: