$ cat "

Setting the Default Database for a SQL Server User

"

Quite often a given SQL Server user is primarily used with one specific database on a server. To make life a little easier you can set the default database for a user, so that new queries by default are run against that database, etc. Here is how to do it in T-SQL:

ALTER LOGIN [SomeLogin] WITH DEFAULT_DATABASE = SomeDatabaseName

A word of warning, if you for some reason drop the database which is set as the default for a user then that user will not be able to log in. If that problem occurs you can change the database to log in to in the Options tab of the SQL Server Management Studio login dialog.

If you manage to log in to SSMS you can then change the default database for the user back to another database which actually still exists, using the example above.

Written by Erik Öjebo 2014-03-04 20:38

    Comments