Schemas

Understanding the tables and schemas in different databases involves querying the system catalog or information schema, which provides metadata about the database's structure. Here’s a brief overview for a few common database systems:

SQL Server

  • Query System Catalog:

    SELECT * FROM INFORMATION_SCHEMA.TABLES;

    This command lists all tables including their table schema in the database.

MySQL

  • Show Tables and Schemas:

    SHOW TABLES;

    This command displays all tables in the current database. To find out which database you are currently using:

    SELECT DATABASE();

    To list all schemas (databases):

    SHOW DATABASES;

PostgreSQL

  • Query Information Schema:

    SELECT table_schema, table_name FROM information_schema.tables
    WHERE table_schema NOT IN ('information_schema', 'pg_catalog');

    This command filters out system tables and shows user-defined tables and their schemas.

Oracle

  • List Tables:

    SELECT table_name FROM user_tables;

    This command shows all tables owned by the current user. To see tables across all schemas you can query:

    SELECT owner, table_name FROM all_tables;

Each database system has its own set of system tables or information schema views that can be queried to understand the database structure, such as schemas, tables, columns, and relationships. These tools are crucial for database management and schema exploration.

Last updated