sqlcmd.net validated sql reference
beginner metadata MySQL MariaDB SQL Server PostgreSQL SQLite

List Tables

Inspect the current database or schema to see which tables exist.

Docker-validated Not currently validation-green

List a small set of created tables

This is a good example of a concept page with engine-specific SQL rather than one universal statement.

MySQL MariaDB
Engine-specific syntax
Setup
CREATE TABLE alpha (id INT);

CREATE TABLE beta (id INT);
SQL
SELECT
  table_name AS table_name
FROM
  information_schema.tables
WHERE
  table_schema = DATABASE ()
  AND table_name IN ('alpha', 'beta')
ORDER BY
  table_name;
table_name
alpha
beta
SQL Server
Engine-specific syntax
Setup
CREATE TABLE alpha (id INT);

CREATE TABLE beta (id INT);
SQL
SELECT
  TABLE_NAME
FROM
  INFORMATION_SCHEMA.TABLES
WHERE
  TABLE_TYPE = 'BASE TABLE'
  AND TABLE_NAME IN ('alpha', 'beta')
ORDER BY
  TABLE_NAME;
TABLE_NAME
alpha
beta
PostgreSQL
Engine-specific syntax
Setup
CREATE TABLE alpha (id INT);

CREATE TABLE beta (id INT);
SQL
SELECT
  table_name
FROM
  information_schema.tables
WHERE
  table_schema = 'public'
  AND table_name IN ('alpha', 'beta')
ORDER BY
  table_name;
table_name
alpha
beta
SQLite
Engine-specific syntax
Setup
CREATE TABLE alpha (id INT);

CREATE TABLE beta (id INT);
SQL
SELECT
  name
FROM
  sqlite_master
WHERE
  type = 'table'
ORDER BY
  name;
name
alpha
beta

The row values are equivalent, but the query shape and generated column labels differ by engine.

Where this command helps.

  • exploring an unfamiliar database
  • confirming that setup scripts created the expected tables

What the command is doing.

Table-listing queries are useful for orientation and metadata discovery, but they are one of the first places where engine-specific syntax becomes visible.