Use [database name] -- Is there something for server name?

  • You can specify which database to use by issuing:

    Use [databasename]

    Is there something like this where you can specify which server or instance to use?

  • isqlw -Sservername

  • Is there a T-SQL command to do this? 

    (instead of specifying the server name when opening QA from a command prompt)

  • Openquery if you have linked server

    or

    openrowset

  • I don't think that this is what I had in mind.  Let me explain.  I am migrating all databases for one server to another server.  In Query Analyzer, I have set up commands to detach a database on Server_OLD (must be connected to Server_OLD).  I then copy the database files to the new server.  Then, in another window in Query Analyzer (connected to Server_NEW), I have commands that attach the database to Server_NEW.  I could combine all of these commands into one window if I had something like the following instead of toggling between two different query windows:

    Use [Server_OLD]

    exec sp_detach_db 'Database_1'

    -- Now move the files --

    Use [Server_NEW]

    exec sp_attach_db 'Database_1,

     'k:\Data\Database_1_Data.MDF',

     'k:\Data\Database_1_Log.LDF'

    Any ideas???

    (I know, I'm lazy)

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

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