Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get all the database names in a sql server instance using tsql?

How can I get all the database names in a sql server instance using tsql?

like image 667
Just a learner Avatar asked May 25 '10 07:05

Just a learner


People also ask

What is the query to list all the databases?

1. System databases: The command to see system databases are : SELECT name, database_id, create_date FROM sys.

How do I get all database objects in SQL Server?

We can use system catalog view sys. objects to view all objects in a SQL database. It has a column type that contains the object category. For example, if we want to search only for the user-defined table, we use 'U' value for the type column.


2 Answers

SELECT * FROM sys.databases 
like image 66
Thomas Avatar answered Oct 26 '22 21:10

Thomas


----SQL SERVER 2005 System Procedures

EXEC sp_databases EXEC sp_helpdb 

----SQL 2000 Method still works in SQL Server 2005

SELECT name FROM sys.databases SELECT name FROM sys.sysdatabases 

----SQL SERVER Un-Documented Procedure

EXEC sp_msForEachDB 'PRINT ''?''' 

to know more about database : http://blog.sqlauthority.com/2007/05/12/sql-server-2005-list-all-the-database/

like image 43
Pranay Rana Avatar answered Oct 26 '22 21:10

Pranay Rana