In this example, i have told you that how to get all databases name in MS SQL 2005/2008. Well, you can get all databases name by using SQL query and by using build in store procedure.
Here's the example
Following is the Query
SELECT *
FROM SYS.DATABASES
Following is the build in store procedure.
EXEC SP_DATABASES