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 2000 Forums
 Transact-SQL (2000)
 Databases Names On The Server

Author  Topic 

schinni
Yak Posting Veteran

66 Posts

Posted - 2004-01-16 : 09:57:46
hello!

Can i get the database names from the sql query
other than using this
Select name from sysdatabases
All i want to find out is if there is way of getting database name
other than using sysdatabases ..

Thanks in advance,

setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2004-01-16 : 10:04:58
If sysdatabases works for you, what's the reason for trying to find another way?

Jonathan
Gaming will never be the same
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-01-16 : 10:33:52
Try this:

EXEC sp_MSForEachDb 'USE ? PRINT DB_NAME()'


Raymond
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-01-16 : 12:35:17
Sysdatabases is the way to go according to your brief question. But what you are trying to do?

Tara
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-01-17 : 17:37:43
quote:
Try this:

EXEC sp_MSForEachDb 'USE ? PRINT DB_NAME()'
It's even easier than that:

EXEC sp_MSForEachDb 'PRINT ''?'''

Although I have to echo the question "Why not use sysdatabases?", it's the easiest and best method available. sp_MSForEachDB uses it anyway.
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2004-01-18 : 18:41:17
Did you just want the CURRENT database name? Then just use SELECT DB_NAME()

--------------------------------------------------------------
Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2004-01-18 : 18:53:32
You can also use schemata information_schema view.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ia-iz_4pbn.asp

Go to Top of Page
   

- Advertisement -