Given an instance of SQL server, what’s the best way to enumerate the databases?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In SQL Server 2000+:
select * from sysdatabasesIn SQL Server 2005+:
select * from sys.databasesThe difference is subtle and barely worth mentioning for a one-liner like this. But depending on how much you’re going to be accessing the system catalog, you may get some use out of this article:
Querying the SQL Server System Catalog
You can also execute
sp_helpdbwithout an argument to get basic information about all databases. (Pass in a database name as an argument to get more detailed information about that database).