Skip to content

02 SQL ‐ Show Tables

Pankaj Chouhan edited this page Sep 29, 2023 · 1 revision

To display a list of tables in a SQL database, you can use a database-specific command. The command may vary depending on the database management system you are using. Here are examples for some popular database systems:

  1. MySQL and MariaDB:

    To list all tables in the current database, you can use the SHOW TABLES command or query the information_schema database:

    Using SHOW TABLES:

    SHOW TABLES;

    Using information_schema:

    SELECT table_name
    FROM information_schema.tables
    WHERE table_schema = 'your_database_name';

    Replace 'your_database_name' with the name of your database.

  2. PostgreSQL:

    To list all tables in the current schema, you can use the following query:

    SELECT table_name
    FROM information_schema.tables
    WHERE table_schema = 'public';

    This query lists tables in the "public" schema, which is the default schema in PostgreSQL. Replace 'public' with the name of your schema if you are using a different one.

  3. SQL Server:

    To list all tables in the current database, you can use a query like this:

    SELECT table_name = t.name
    FROM sys.tables t
    INNER JOIN sys.schemas s ON t.schema_id = s.schema_id;

    This query retrieves tables and their schema names.

Please ensure that you have appropriate permissions to view the tables in the database. The specific syntax and commands may vary depending on the database management system you are using, so consult your database system's documentation for details specific to your environment.

Clone this wiki locally