Author |
Topic |
rajendradhakal
Starting Member
11 Posts |
Posted - 2010-10-11 : 09:54:11
|
How to detect already created database?Rajendra DhakalDO 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 ShawSQL Server MVP |
|
|
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 DhakalDO good, Wish Good and so on |
|
|
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.databasesIf not exists(Select 1 from sys.databases where name = 'Yourdbname')Create database yourdatabasename |
|
|
rajendradhakal
Starting Member
11 Posts |
Posted - 2010-10-11 : 10:27:28
|
can i get full query, which help me to get easilyRajendra DhakalDO good, Wish Good and so on |
|
|
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 easilyRajendra DhakalDO 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. |
|
|
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 DhakalDO good, Wish Good and so on |
|
|
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 |
|
|
rajendradhakal
Starting Member
11 Posts |
Posted - 2010-10-11 : 11:09:19
|
yes this is sql server 2000Rajendra DhakalDO good, Wish Good and so on |
|
|
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 ShawSQL Server MVP |
|
|
|