Showing posts with label available. Show all posts
Showing posts with label available. Show all posts

Wednesday, March 28, 2012

How to enumerate the databases on the server

Given that you have an interface with a connection to SQL Server Express, is there some T-SQL script or statement that can enumerate the available database names on the server ?

For example:

CString clQuery;

clQuery.Format("SELECT SERVERPROPERTY('Databases')");

m_db.Execute(clQuery);

or something of the sort ?

This will work in both SQL 2000 and SQL 2005:

Code Snippet


SELECT CATALOG_NAME
FROM INFORMATION_SCHEMA.SCHEMATA

|||

Thanks, Arnie.

For some reason, that statement only yields about 16 'Master' records in the CATALOG_NAME column. I really need a way to enumerate all the databases on the server.

Any other ideas ?

Mike

|||

Sorry Mike, my mistake. That Information VIEW 'changed' between SQL 2000 and SQL 2005.

In SQL 2005, use:

SELECT name

FROM sys.databases

|||

Thanks, Arnie. That works perfectly.

BTW, I have had trouble responding as your server appears to be down quite a bit of the time.

Regards,

Mike

|||There seems to have been some 'replication' issues this week. We all appreciate everyone's patience/