Groups | Blog | Home
all groups > vb.net data > june 2005 >

vb.net data : Checking to see if a database exists


Jim Hughes
6/29/2005 1:53:37 PM
You have to specify a table, not a database.

IF NOT EXISTS(SELECT * FROM databasename.owner.tablename)

e.g.

IF NOT EXISTS(SELECT * FROM pubs.dbo.authors)

[quoted text, click to view]

RSH
6/29/2005 3:08:31 PM
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

Programmer
6/30/2005 12:00:00 AM
To check if a database exist you have to run in SQL this
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
N'MyDatatabaseName')




[quoted text, click to view]

AddThis Social Bookmark Button