H2 Introduction
Understanding how to SQL list all tables in database is a fundamental skill for developers, database administrators, and analysts who need to inspect the structure of a relational database quickly. Whether you are exploring a new schema, debugging a query, or preparing documentation, knowing the exact names of tables saves time and prevents errors. This article explains the standard, cross‑platform methods to retrieve table listings, provides concrete examples for the most popular database engines, and offers tips for customizing the output to suit specific needs That's the part that actually makes a difference. And it works..
H2 Using the INFORMATION_SCHEMA Views
The INFORMATION_SCHEMA is a standardized set of views defined by the SQL standard that stores metadata about database objects. Almost every relational DBMS implements it, making it the most portable way to list tables. The key view for table names is TABLES, which contains one row per table (and view) in the catalog.
- The
TABLE_TYPEcolumn distinguishes tables from views ('BASE TABLE'vs.'VIEW'). - The
TABLE_SCHEMAcolumn indicates the schema (or database) the table belongs to.
A basic query that returns every base table across all schemas looks like this:
SELECT TABLE_NAME, TABLE_SCHEMA
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_SCHEMA, TABLE_NAME;
Why this works: The WHERE clause filters out views, ensuring you only see actual tables. Ordering by schema and name makes the result easier to scan.
H3 Customizing the INFORMATION_SCHEMA Query
You can refine the list in several useful ways:
- Limit to a single schema – add
AND TABLE_SCHEMA = 'your_schema'. - Exclude system tables – many engines expose internal schemas like
information_schemaorsys. Filter them out withAND TABLE_SCHEMA NOT IN ('information_schema', 'sys'). - Include views – change the filter to
TABLE_TYPE IN ('BASE TABLE', 'VIEW')if you need both.
These modifications keep the query lightweight and relevant to your current project.
H2 System Catalog Views Specific to Each DBMS
While INFORMATION_SCHEMA works everywhere, some databases expose richer catalog views that provide additional details such as table owners, creation dates, or indexes. Below are the most common alternatives That's the part that actually makes a difference..
H3 PostgreSQL – pg_catalog
PostgreSQL stores its metadata in the pg_catalog schema. The query below returns all tables, including schema name and whether the table is partitioned:
SELECT n.nspname AS schema_name,
c.relname AS table_name,
CASE WHEN c.relkind = 'r' THEN 'BASE TABLE'
WHEN c.relkind = 'v' THEN 'VIEW'
ELSE 'OTHER'
END AS object_type
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v')
ORDER BY n.nspname, c.relname;
Key points: relkind = 'r' denotes a regular table, while 'v' denotes a view.
H3 MySQL – INFORMATION_SCHEMA.TABLES (again)
MySQL also relies on INFORMATION_SCHEMA, but you can add the TABLE_CATALOG filter to target a specific database:
SELECT TABLE_NAME, TABLE_SCHEMA
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_CATALOG = DATABASE()
ORDER BY TABLE_SCHEMA, TABLE_NAME;
This ensures you only see tables belonging to the current database, ignoring other databases that may be attached to the same server.
H3 SQL Server – sys.tables
SQL Server uses the sys catalog views. The simplest way to list user tables is:
SELECT s.name AS schema_name,
t.name AS table_name,
t.type_desc AS object_type
FROM sys.tables t
JOIN sys.schemas s ON s.schema_id = t.schema_id
WHERE t.is_ms_shipped = 0
ORDER
BY s.name, t.name;
Why the is_ms_shipped = 0 filter: SQL Server includes internal system tables in sys.tables. This flag excludes them, leaving only user-defined objects The details matter here..
H3 Oracle – ALL_TABLES / USER_TABLES / DBA_TABLES
Oracle provides three flavors of the same catalog view, differing only in scope:
| View | Scope | Typical Use |
|---|---|---|
USER_TABLES |
Tables owned by the current user | Quick, no privileges needed |
ALL_TABLES |
Tables accessible to the current user | Most common for developers |
DBA_TABLES |
Every table in the database | Requires DBA role |
A portable query using ALL_TABLES:
SELECT owner AS schema_name,
table_name,
'BASE TABLE' AS object_type
FROM all_tables
WHERE owner NOT IN ('SYS','SYSTEM','SYSAUX','XDB','ORDSYS','MDSYS','CTXSYS')
ORDER BY owner, table_name;
Notes:
- The
OWNERcolumn maps to schema. - The
NOT INlist removes Oracle-maintained schemas; adjust if you have custom administrative schemas.
H3 SQLite – sqlite_master
SQLite keeps its schema in a single system table called sqlite_master (alias sqlite_schema in newer versions).
SELECT type,
name AS table_name,
sql AS definition
FROM sqlite_master
WHERE type IN ('table','view')
AND name NOT LIKE 'sqlite_%'
ORDER BY type, name;
Key points:
type = 'table'for base tables,'view'for views.- The
sqlcolumn holds the originalCREATEstatement—handy for quick DDL inspection. - Internal objects (e.g.,
sqlite_sequence) are prefixed withsqlite_; theNOT LIKEfilter hides them.
H3 Snowflake – INFORMATION_SCHEMA + SHOW TERSE
Snowflake supports the standard INFORMATION_SCHEMA.TABLES but also offers a concise command:
SHOW TERSE TABLES IN ACCOUNT;
Output columns include database_name, schema_name, name, kind (TABLE, VIEW, EXTERNAL TABLE, etc.The TERSE keyword suppresses secondary properties (retention time, clustering keys, etc.Now, ), and owner. ) for a cleaner list.
H3 BigQuery – INFORMATION_SCHEMA.TABLES
BigQuery follows the standard but requires a project-qualified dataset prefix:
SELECT table_catalog AS project_id,
table_schema AS dataset_id,
table_name,
table_type
FROM `my-project`.region-us.INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE'
ORDER BY table_schema, table_name;
Replace my-project and region-us with your actual project ID and region.
H2 Choosing the Right Approach
| Scenario | Recommended Method |
|---|---|
| Cross-database scripts / portability | INFORMATION_SCHEMA.Worth adding: tABLES |
| Need creation date, owner, partitioning, or storage details | Native catalog views (pg_class, sys. Think about it: tables, ALL_TABLES, etc. ) |
| Ad-hoc interactive exploration | SHOW TABLES (MySQL/MariaDB), \dt (psql), SHOW TERSE TABLES (Snowflake) |
| Programmatic access from application code | INFORMATION_SCHEMA (stable, standard) or driver-specific metadata APIs (`DatabaseMetaData. |
H2 Performance Considerations
- INFORMATION_SCHEMA views are often implemented as complex joins over system tables; on databases with thousands of tables they can be slower than native catalog queries.
- Filter early: always restrict by
TABLE_SCHEMA/OWNER/schema_idbefore joining additional catalog tables. - Cache results if you repeatedly enumerate tables in a long-running process; catalog metadata changes infrequently.
H2 Security & Permissions
- Standard
INFORMATION_SCHEMAvisibility respects the current user’s privileges—you only see objects you have at leastSELECTorUSAGEon. - Native catalog views may require elevated roles (
VIEW DEFINITIONin SQL Server,SELECT_CATALOG_ROLEin Oracle) to see objects outside your own schema. - Audit-sensitive environments often restrict direct catalog
access to INFORMATION_SCHEMA entirely, forcing DBAs to use approved metadata APIs or dedicated inventory tables.
- Row-level security policies on catalog views (supported in PostgreSQL 15+ and SQL Server 2022+) can further limit visibility to specific schemas or table classifications.
H2 Common Pitfalls & Quick Fixes
| Symptom | Likely Cause | Fix |
|---|---|---|
INFORMATION_SCHEMA.So tABLES returns zero rows |
Connected to wrong database / schema search path | SET search_path TO target_schema; (PostgreSQL) or USE target_db; (MySQL/SQL Server) |
SHOW TABLES lists views but you need only base tables |
Default behavior includes views | SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'; (MySQL/MariaDB) |
Oracle ALL_TABLES misses tables you just created |
Transaction not committed; DDL is implicit commit in Oracle, but synonyms/grants may lag | COMMIT; then re-query; ensure you own the table or have SELECT ANY TABLE |
Snowflake SHOW TERSE TABLES truncates names at 255 chars |
Historical UI limit | Use INFORMATION_SCHEMA. TABLES for full-length identifiers |
BigQuery query fails with “Table not found” on INFORMATION_SCHEMA |
Missing project/region prefix | Fully qualify: `` `project.Also, region. INFORMATION_SCHEMA. |
H2 Automating Schema Inventory
For repeatable, version-controlled inventories, wrap the native queries in a parameterized script. Example (Bash + psql):
#!/usr/bin/env bash
# inventory.sh — emits CSV: schema,table,type,owner,created
DB_URL=${1:? "Usage: inventory.sh postgresql://user:pwd@host/db"}
psql "$DB_URL" -Atc "
SELECT n.relname AS table,
CASE c.On top of that, nspname <> 'information_schema'
ORDER BY n. nspname AS schema,
c.nspname, c.Plus, oid = c. In practice, relnamespace
WHERE c. Practically speaking, relkind::text END AS type,
pg_get_userbyid(c. Still, nspname NOT LIKE 'pg_%'
AND n. Day to day, relkind WHEN 'r' THEN 'TABLE' WHEN 'v' THEN 'VIEW' ELSE c. relkind IN ('r','v','p','f') -- tables, views, partitioned, foreign
AND n.relcreated
FROM pg_class c
JOIN pg_namespace n ON n.Day to day, relowner) AS owner,
c. relname;
" | sed 's/|/,/g' > inventory_$(date +%F).
Equivalent patterns exist for `sqlcmd` (SQL Server), `sqlplus` (Oracle), `snowsql`, and `bq` CLI—standardize on CSV/JSON output and load into a central metadata lake for lineage tooling.
# H2 Conclusion
Listing tables is the entry point to every data engineering workflow—impact analysis, governance audits, migration planning, or simple exploration. The ANSI `INFORMATION_SCHEMA.TABLES` view gives you a portable baseline, yet each platform’s native catalog (`pg_class`, `sys.That said, tables`, `ALL_TABLES`, `TABLES_V`, etc. ) exposes richer metadata: partitioning schemes, clustering keys, retention policies, and exact DDL.
Choose the standard view for cross-database scripts and application code; reach for native catalogs when you need performance, granular storage details, or DDL reconstruction. Also, filter early, cache aggressively, and respect the permission model of each engine. With the quick-reference snippets and automation patterns above, you can inventory any fleet—from a single PostgreSQL instance to a multi-cloud estate spanning Snowflake, BigQuery, and Oracle—consistently and reliably.