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

后端 未结 11 1786
遥遥无期
遥遥无期 2020-11-30 17:48

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 Man

11条回答
  •  萌比男神i
    2020-11-30 18:24

    This may or may not exactly answer the question, but I ran into this issue (and question) when I had changed my account to have a new database I had created as my "default database". Then I deleted that database and wanted to test my creation script, from scratch. I logged off SSMS and was going to go back in, but was denied -- cannot log into default database was the error. D'oh!

    What I did was, on the login dialog for SSMS, go to Options, Connection Properties, then type master on the "Connect to database" combobox. Click Connect. Got me in. From there you can run the command to:

    ALTER LOGIN [DOMAIN\useracct] WITH DEFAULT_DATABASE=[master]
    GO
    

提交回复
热议问题