Checking to see if a database exists...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RSH

    #1

    Checking to see if a database exists...

    I'm creating databases programatically in .Net and I want to verify that the
    database doesn't exist before creating it. i found the SQL code:

    IF NOT EXISTS(SELECT * FROM <databasename >)

    But when I run the code against a known database, even in SQL Management
    Studio I get a "Incorrect syntax near ')' error.

    What am i doing wrong?

    Thanks
    RSH


  • Mike Labosh

    #2
    Re: Checking to see if a database exists...

    > I'm creating databases programatically in .Net and I want to verify that[color=blue]
    > the
    > database doesn't exist before creating it. i found the SQL code:[/color]

    IF EXISTS (
    SELECT *
    FROM Information_Sch ema.Schemata
    WHERE Catalog_Name = 'YourDatabaseNa me'
    )
    /* Database Exists */
    ELSE
    /* Database does not exist */

    --
    Peace & happy computing,

    Mike Labosh, MCSD

    "Mr. McKittrick, after very careful consideration, I have
    come to the conclusion that this new system SUCKS."
    -- General Barringer, "War Games"


    Comment

    Working...