How to change the default database using SQL Server Management Studio

Posted on 2006-03-22
Last Modified: 2013-12-03
I don't see how to change the default database.

I have an ODBC connection in which I can tell it to use a different database than what the default database is, but if I delete that default database the ODBC connections fail. So I need to change the default database.
Question by:kzsigo
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    try this query

    exec sp_defaultdb 'LoginName', 'NewDefltDBName'

    This works in SQL 2k

    Author Comment

    this ran without an error, but did not seem to work.
    LVL 75

    Accepted Solution

    exec sp_defaultdb 'sa', 'msdb'

    run the above and logon to ur sql server using 'sa' and check the dbname, it has to be msdb, earlier it was master

    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    Points to aneeshattingal

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now