Friday, 1 April 2016

How to Change the Default Database in SQL Server ?

While opening a new query window,Initially the selected database will be Master 
To change the Default database in SQL server while login use the following syntax.

Syntax : 
EXEC SP_DEFAULTDB 'LOGIN NAME','DATABASE NAME'


Example :

EXEC SP_DEFAULTDB 'SA','SAMPLE'


Login Name -- Refers to the SQL server login Name
Database Name -- Refers to the default database Name


After executing the above system stored procedure ,the default database will be changed from master database to Sample database.

In next login the default selected database will be Sample.

No comments:

Post a Comment