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. 

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

Leave a Comment

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