Change Database Connection in SQL Server

Change Database Connection in SQL Server

In general, every user tends to work on a separate database on the server during the development phase of an application. It can be annoying for users to repeatedly change the default database to the one to which they are connected when logging on to SQL Server. You can change the database connection using the stored procedure sp_defaultdb:

 sp_defaultdb login_id, defaultdb

After sp_defaultdb is executed, users are connected to the new defaultdb the next time they log in. However, this stored procedure does not automatically give users access to that database. The database owner must explicitly give access to the users. If no default database has been specified, users are connected to the master database. Execute permission for this procedure defaults to public for a user’s login ID only and to the system administrator for any login ID.


Share the Post: