How can I get all the database names in a sql server instance using tsql?
1. System databases: The command to see system databases are : SELECT name, database_id, create_date FROM sys.
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.
SELECT * FROM sys.databases
----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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With