sql help

  • how do i change connection database from master database to own database please

  • From an application? When you connect to Management Studio? Something else?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • You can change the default database in the properties of the LOGIN you are using. This is the most helpfull way if you only need to access one single database.

    You can execute the "USE [your_databasename];" command before your SQL statements if you need to change the scope to another database.

    In most (or all?) connection strings (like for an ODBC connection) you can specify the desired database you initially want to connect to.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • This was removed by the editor as SPAM

  • sqladmin 33439 (6/12/2014)


    how do i change connection database from master database to own database please

    In T-SQL there are two main options, either use a system stored procedure sys.sp_defaultdb or ALTER LOGIN, recommend the former as it adds validity checks for the login and the database name. It also checks for open transactions.

    😎

    /* The command for changing the default db

    */

    ALTER LOGIN [login_name] WITH DEFAULT_DATABASE = [database_name];

    /* System procedure which adds validity checks before executing

    the command above

    */

    EXEC sys.sp_defaultdb [login_name], [database_name];

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply