detach db

  • _______________________________________________________

    DECLARE @strSQL1 Varchar(MAX)

    StrSQL2 = 'SELECT state_desc FROM sys.databases where name = 'dbname' '

    if state_desc = 'ONLINE'

    exec sp_detach_db @dbname='dbname'

    else

    print @StrSQL1

    _____________________________________________________

    I am trying to prepare a script(above) by using the Logic: 1st check Db is online if yes then Detach dB, If no ignore .

    Any suggestions pls for above code.

  • my script is working.

    Thanks.

  • charipg (6/21/2015)


    my script is working.

    Thanks.

    Can you post the script that's actually working for you please? Thanks.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

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