Checking to see if a database exists...

R

RSH

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
 
M

Mike Labosh

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 EXISTS (
SELECT *
FROM Information_Schema.Schemata
WHERE Catalog_Name = 'YourDatabaseName'
)
/* 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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top