Knowing the exact sql query to list tables in a database is one of the first skills every developer, data analyst, or database administrator needs when working with relational systems. Whether you are exploring a new project, auditing an existing schema, or writing dynamic reports, being able to retrieve a complete list of tables helps you understand the data structure without opening a graphical interface. This guide walks you through the most reliable methods across popular database platforms, explains how to filter results, and shows you how to avoid common pitfalls when querying table metadata.
Easier said than done, but still worth knowing.
Why You Need to List Tables in a Database
Databases often contain dozens, hundreds, or even thousands of tables. In a production environment, you might not have immediate documentation for every object. Running a query to list all tables gives you a quick inventory of what is available, which is especially useful when:
- Onboarding to a new project with an unfamiliar schema
- Verifying that a migration script created the expected tables
- Building dynamic dashboards that discover tables automatically
- Auditing database objects for security or compliance purposes
- Debugging application errors related to missing or misspelled table names
Instead of guessing table names or clicking through a GUI, a well-written SQL query returns accurate, up-to-date metadata directly from the database engine.
The Universal Approach: Using INFORMATION_SCHEMA
Most modern relational databases support the ANSI-standard INFORMATION_SCHEMA, a virtual schema that provides read-only access to metadata about tables, columns, views, and other objects. Because it is standardized, the same core logic works across many platforms with only minor syntax adjustments Simple as that..
To list tables using INFORMATION_SCHEMA, you typically query the TABLES view:
SELECT table_name
FROM information_schema.tables
WHERE table_type = 'BASE TABLE';
This query returns only actual tables and excludes views, system tables, and temporary objects. The table_type column is important because INFORMATION_SCHEMA.In real terms, tABLES often includes views by default. If you want both tables and views, you can omit the WHERE clause or adjust it to include 'BASE TABLE' and 'VIEW'.
The INFORMATION_SCHEMA approach is portable, which means you can use similar syntax in MySQL, PostgreSQL, SQL Server, and other systems. Still, each database engine also provides native shortcuts that are often faster to type and easier to remember.
Database-Specific SQL Queries to List Tables
While INFORMATION_SCHEMA is universal, most database administrators prefer native commands for day-to-day work. Below are the most common ways to list tables in the major database systems.
MySQL and MariaDB
MySQL offers a simple, dedicated command:
SHOW TABLES;
This returns a single column containing the names of all tables in the currently selected database. If you want more detail, such as the table type or engine, you can query INFORMATION_SCHEMA:
SELECT table_name, table_type, engine
FROM information_schema.tables
WHERE table_schema = DATABASE();
The DATABASE() function ensures you are only looking at the active database, which is helpful when you manage multiple databases on the same server.
PostgreSQL
PostgreSQL does not have a SHOW TABLES command by default. Instead, you query the pg_catalog schema or use INFORMATION_SCHEMA:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE';
The public schema is the default in PostgreSQL, but your tables might reside in custom schemas. You can also use the pg_tables view for a quicker look:
SELECT tablename
FROM pg_catalog.pg_tables
WHERE schemaname = 'public';
Many PostgreSQL users also rely on the psql command-line meta-command \dt, which lists tables in a formatted output, though this is a client feature rather than pure SQL That's the part that actually makes a difference..
Microsoft SQL Server
SQL Server provides several options. The simplest is to query the system view sys.tables:
SELECT name AS table_name
FROM sys.tables;
You can also use INFORMATION_SCHEMA, which works well for cross-platform scripts:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'dbo'
AND table_type = 'BASE TABLE';
In SQL Server, dbo is the default schema, but user-defined schemas are common. Always specify the schema if you are not working in the default one.
Oracle Database
Oracle organizes metadata through data dictionary views. To list tables owned by the current user
Oracle’s data dictionary is built on a set of views that are owned by the various privileges you hold. The most direct way to see every table that belongs to you is:
SELECT table_name
FROM user_tables;
If you have the privilege to view objects across schemas, ALL_TABLES returns tables you can access, and DBA_TABLES (available only to users with the DBA role) exposes the complete catalog. To filter out views and keep only real tables, add the TABLE_TYPE column:
SELECT table_name, table_type
FROM user_tables
WHERE table_type = 'BASE TABLE';
Oracle also supports the standard INFORMATION_SCHEMA views, so the portable query works as well:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = USER
AND table_type = 'BASE TABLE';
SQLite
SQLite does not expose a traditional schema catalog. Instead, it offers a pragma that lists the tables in the current database:
PRAGMA table_list;
The result set includes the table name, type (e.g., 'table' or 'view'), and other metadata And that's really what it comes down to..
SELECT name AS table_name
FROM sqlite_master
WHERE type = 'table';
DB2
DB2 provides a set of catalog views under the SYSIBM schema. The most common query to retrieve user tables is:
SELECT tabname AS table_name
FROM syscat.tables
WHERE owner = USER
AND type = 'T';
If you need to include views as well, change the type filter to 'V'.
Snowflake and Other Cloud Data Warehouses
Modern cloud platforms often implement the ANSI‑standard INFORMATION_SCHEMA views, making the same query work across Snowflake, Redshift, BigQuery, and Azure Synapse. As an example, in Snowflake:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = CURRENT_SCHEMA
AND table_type = 'BASE TABLE';
Putting It All Together
Across relational systems, the underlying concept is the same: a system‑maintained catalog stores metadata about every object you create. Practically speaking, the portable INFORMATION_SCHEMA approach gives you a single, ANSI‑compliant syntax that works from MySQL to Oracle, PostgreSQL to Snowflake. Practically speaking, when you are writing ad‑hoc scripts or quick checks, the native shortcuts—SHOW TABLES in MySQL, \dt in psql, SELECT name FROM sys. tables in SQL Server, SELECT table_name FROM user_tables in Oracle, and PRAGMA table_list in SQLite—save keystrokes and reduce verbosity.
Choosing between the universal query and the database‑specific command depends on three factors:
- Portability – If you need the same script to run on multiple platforms, stick with
INFORMATION_SCHEMA. - Readability – Native commands are often shorter and more intuitive for the local environment.
- Privileges – Some catalog views (e.g.,
DBA_TABLESin Oracle) require elevated rights; a schema‑restricted view likeuser_tablesmay be all you can access.
By understanding both the standard and the native options, you can write flexible, maintainable SQL code that adapts to the database you are working with while keeping your queries clean and efficient.
Conclusion
Listing tables is a routine task that every database professional encounters, and each RDBMS offers a straightforward path—whether through a dedicated command, a system view, a pragma, or the standard INFORMATION_SCHEMA. Leveraging the native shortcuts makes everyday work quicker, while the portable queries ensure your code remains reusable across diverse environments. Mastering both approaches gives you the flexibility to operate confidently in any SQL‑based ecosystem And that's really what it comes down to. Took long enough..