If you’re working with SQL Server and need to explore your database structure, this script will help you list all databases and their corresponding tables quickly. Whether you’re a database administrator, developer, or data analyst, having a clear overview of your SQL Server environment is essential. In this guide, we’ll walk through a simple SQL script that retrieves all database names along with the tables they contain. This is especially useful for auditing, documentation, or managing large-scale SQL Server instances. Follow along to streamline your database discovery process with this SQL Server query.
below is the output of the queries, for all the databases and then another query for all the tables. note that the tables query, will give you all the tables in the database session you are using, so make sure to change it to the databases you want. I have iterated through the collection of tables with msp_foreach in the past.


With this SQL Server script, you can quickly gain insight into all your databases and their tables in one go. It’s a practical tool for managing, auditing, or documenting your SQL Server environment. Save time and reduce manual effort by automating database discovery. Start using this script today to streamline your SQL Server workflows.