Welcome to SqlAdvice Sign in | Join | Help

Change Login's Default Database in SQL Server

If you have ever dropped a database and found yourself not able to login because your default database no longer exists you know it can be quite annoying.  You can still connect through query analyzer by connecting to a different database, but you won't be able to do anything through the object explorer as it always defaults to your default database.  The sql below will solve your problems.

alter login MyLogin with default_database = master

If you need to alter a login that is using windows authentication use the following code.  The only difference is you just have to specify the domain and the directory login and put it in brackets. 

alter login [MyDomain\MyLogin] with default_database = master

I hope this helps and if not at least I will be able to easily find the solution next time I run into it. 

Sponsor
Published Tuesday, October 16, 2007 8:18 AM by gstark

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Thursday, October 25, 2007 8:29 AM by asd

# re: Change Login's Default Database in SQL Server

good

Thursday, July 09, 2009 11:22 AM by Jonathan

# re: Change Login's Default Database in SQL Server

Excellent resolution! I managed to make my way into the SQL Mgmt Studio and SQLCMD tools, but couldn't get the default_database to change.

My formatting and syntax for the command (using a windows credential account) was incorrect. The Microsoft site was useless, as were many other sites.

I tried () brackets and '' quotation marks.

Thx for the clarification on the [] brackets, worked great!

Wednesday, November 04, 2009 5:54 PM by Heavy D

# re: Change Login's Default Database in SQL Server

Dude,

You so rock.  Thanks for helping out a newbie! :)

Saturday, August 21, 2010 1:04 PM by Baluk

# re: Change Login's Default Database in SQL Server

Hi,

Thanks for the post. it really saved my time to set the master databse back as a default for login.

Thank you,

baluk

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below