Feb 9, 2014

Set default database in sql server management studio (SSMS)


How to set default database in SQL Server management studio (SSMS)

Default database in sql server depends upon user i.e. each user can have his own default data base.
SQL query to get the current user.

DECLARE @User AS VARCHAR(1000)
SET @User = SUSER_NAME()
SELECT @User

Or
DECLARE @User AS VARCHAR(1000)
SET @User = SYSTEM_USER
SELECT @User

SQL Query to set the any database as default database:

EXECUTE SP_DEFAULTDB @loginame = 'SELF-06B93520CC\Ritesh kumar', @defdb = 'MyDb'

Here "SELF-06B93520CC\Ritesh kumar" is user name and "MyDb" is any data base name.

No comments:

Post a Comment