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
 Transact-SQL (2005)
 Use code to list all database name

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-08-05 : 10:22:42
How to code to list all database name in a server?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-08-05 : 10:24:21
sp_databases
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2008-08-05 : 10:26:01
I found:
select name from master..sysdatabases
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-05 : 10:34:36
or

select name from sys.databases

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-05 : 13:16:01
quote:
Originally posted by Sun Foster

I found:
select name from master..sysdatabases


This table is available only in sql 2000. If 2005, use sys.databases as suggested by Madhi
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-08-05 : 13:48:09
quote:
Originally posted by visakh16

quote:
Originally posted by Sun Foster

I found:
select name from master..sysdatabases


This table is available only in sql 2000. If 2005, use sys.databases as suggested by Madhi


This works OK in SQL Server 2005:
select name from master..sysdatabases


CODO ERGO SUM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-05 : 13:57:57
quote:
Originally posted by Michael Valentine Jones

quote:
Originally posted by visakh16

quote:
Originally posted by Sun Foster

I found:
select name from master..sysdatabases


This table is available only in sql 2000. If 2005, use sys.databases as suggested by Madhi


This works OK in SQL Server 2005:
select name from master..sysdatabases


CODO ERGO SUM


isnt equivalent view named sys.sysdatabases in sql 2005? I think it was provided for backward compatibility and they recommend using new catalog view sys.databases instead.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-08-05 : 20:50:20
Yes, Visakh is right.They have added new columns.
Go to Top of Page
   

- Advertisement -