How can I change my default database in SQL Server without using MS SQL Server Management Studio?

Martin Brown

I dropped a database from SQL Server, however it turns out that my login was set to use the dropped database as its default. I can connect to SQL Server Management Studio by using the 'options' button in the connection dialog and selecting 'master' as the database to connect to. However, whenever I try to do anything in object explorer, it tries to connect using my default database and fails.

Does anyone know how to set my default database without using object explorer?

Marek

Alternative to sp_defaultdb (which will be removed in a future version of Microsoft SQL Server) could be ALTER LOGIN:

ALTER LOGIN [my_user_name] WITH DEFAULT_DATABASE = [new_default_database]

Note: unlike the sp_defaultdb solution user and database names are provided without quotes. Brackets are needed if name had special chars (most common example will be domain user which is domain\username and won't work without brackets).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Using LIKE in ms sql server management studio

How to send my Database in SQL server management Studio 2019

How can I regain access to MS SQL Server after default database for a user is taken offline?

How can I export the record sets of the view to sql with using SQL Server Management Studio Express?

How can I change the connection for current tab in Microsoft SQL Server Management Studio

Desktop shortcut with Default database for SQL Server Management Studio

How can I create a view in SQL Server Management Studio using different where clause statements in it?

How can I start using MS-SQL Server ( express )

Cannot connect to arvixe database in my SQL Server Management Studio

How can I change properties of FK in SQL Server database project?

How can I change database name in Sql Server with code?

How can I restore my SQL Server database in MSSMS?

How can I detect the changes in my SQL Server database

How can i remove duplicate rows with in my sql server database

How can I see the changes on my SQL server in Visual Studio?

Can't edit rows of Azure database in SQL Server Management Studio

Can't see EF database in SQL Server Management Studio

How can I connect my Flutter app to local sql server database using API?

Cannot connect to RDS SQL Server Database using Management Studio

Having trouble with a database query using SQL Server Management Studio

SQL Server Management Studio ignores default DB

How to connect to a local database in SQL Server Management Studio?

How to delete the contents of a database in SQL Server Management Studio?

How to ensure independency of a database copy in SQL Server Management Studio?

Unable to find database in SQL Server Management Studio

SQL Server Management Studio Database Icons

Is SQL Server Management Studio necessary to use SQL Server database?

Can I have multiple rows of tabs in SQL Server Management Studio

Can I install SQL Server Management Studio on Ubuntu 16.04?