Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 How to detect already created database?

Author  Topic 

rajendradhakal
Starting Member

11 Posts

Posted - 2010-10-11 : 09:54:11
How to detect already created database?

Rajendra Dhakal
DO good, Wish Good and so on

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-10-11 : 10:03:07
Can you be more specific?

If you want to see if a database with a particular name exists, query sys.databases.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

rajendradhakal
Starting Member

11 Posts

Posted - 2010-10-11 : 10:05:00
of course,
I've to create a specific database on SQL server and have to detect already created or not? how to do it?

Rajendra Dhakal
DO good, Wish Good and so on
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-11 : 10:12:42
As said by Gail,

You need to query sys.databases

If not exists(Select 1 from sys.databases where name = 'Yourdbname')
Create database yourdatabasename
Go to Top of Page

rajendradhakal
Starting Member

11 Posts

Posted - 2010-10-11 : 10:27:28
can i get full query, which help me to get easily

Rajendra Dhakal
DO good, Wish Good and so on
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-11 : 10:36:16
quote:
Originally posted by rajendradhakal

can i get full query, which help me to get easily

Rajendra Dhakal
DO good, Wish Good and so on


Isn't it enough what pk_bohra has posted?

If not exists(Select 1 from sys.databases where name = 'Yourdbname')
Create database yourdatabasename



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rajendradhakal
Starting Member

11 Posts

Posted - 2010-10-11 : 10:48:35
Here is not working this code, It says sys.databases [invalid objects]

Rajendra Dhakal
DO good, Wish Good and so on
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-10-11 : 10:53:11
is this SQL 2000?

If so, use sysdatabases instead of sys.databases
Go to Top of Page

rajendradhakal
Starting Member

11 Posts

Posted - 2010-10-11 : 11:09:19
yes this is sql server 2000

Rajendra Dhakal
DO good, Wish Good and so on
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-10-11 : 12:19:24
Replace sys.databases with sysdatabases.

And please don't post SQL 2000 questions in the SQL 2005 forums. It leads to exactly what happened here.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -