dbTalk Databases Forums  

if not exists (database...) create database myDB

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss if not exists (database...) create database myDB in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hans [DiaGraphIT]
 
Posts: n/a

Default if not exists (database...) create database myDB - 11-15-2005 , 11:39 AM






Hi!

As the subjects says i wish to find out if a spesific database exist in my
sql server.

I wish to write following statement.

if not exists (select * from information_schema.databasename where
database_name = 'myDB')
Create Database myDB
GO

But I know i'm missing something.... Please help



---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)

Reply With Quote
  #2  
Old   
Mike Sharpe
 
Posts: n/a

Default RE: if not exists (database...) create database myDB - 11-15-2005 , 02:01 PM






You can query against the sysdatabases table in the Master database to see if
a specified database exists on the server.

This is how we build our databases if they don't already exist.

Reply With Quote
  #3  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: if not exists (database...) create database myDB - 11-15-2005 , 02:13 PM



Wha about

IF (SELECT DB_ID('Name')) IS NULL

....

Allan

"Hans [DiaGraphIT]" <hans.arsjo (AT) sshf (DOT) no> wrote


Quote:
Hi!

As the subjects says i wish to find out if a spesific database exist in
my
sql server.

I wish to write following statement.

if not exists (select * from information_schema.databasename where
database_name = 'myDB')
Create Database myDB
GO

But I know i'm missing something.... Please help



---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)


Reply With Quote
  #4  
Old   
Hans [DiaGraphIT]
 
Posts: n/a

Default RE: if not exists (database...) create database myDB - 11-15-2005 , 11:01 PM



Hi Mike!

I really appreciate your quick respons. This was realy helpfull. Thank you
very much. :-)

---------------
Best regards
- Hans -
---------------
(Have fun programming with ... C#)


"Mike Sharpe" wrote:

Quote:
You can query against the sysdatabases table in the Master database to see if
a specified database exists on the server.

This is how we build our databases if they don't already exist.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.