Displays database, table, and column structure details using SHOW and INFORMATION_SCHEMA queries.
Run SHOW TABLES;
in your current database to return all table names instantly.Add FROM ecommerce;
when connected to another schema.
Use SHOW TABLES LIKE 'ord%';
to retrieve only tables whose names start with ord
, such as Orders
and OrderItems
.
Execute DESCRIBE Orders;
or its synonym SHOW COLUMNS FROM Orders;
to list each column, data type, nullability, default, and key info.
DESCRIBE Orders;
returns columns like id INT PK
, customer_id INT FK
, and total_amount DECIMAL(10,2)
.
Run SHOW CREATE TABLE Products\G
to receive the full CREATE TABLE
statement, including indexes and constraints—ideal for migrations and backups.
Query INFORMATION_SCHEMA.COLUMNS
to aggregate metadata or search across tables.Example: list all DECIMAL
columns in the ecommerce
schema.
SELECT table_name, column_name FROM information_schema.columns WHERE table_schema='ecommerce' AND data_type='decimal';
Work in a read-only client, qualify schema names in multi-db servers, and export results to version control for future reference.
FORGETTING FROM db_name
—returns tables from the wrong database. Always specify the schema when not connected directly.USING DESCRIBE *
—wildcards not allowed; DESCRIBE each table individually or loop in a script.
Combine SHOW CREATE TABLE
with a quick mysqldump --no-data
to capture the entire database schema without row data.
.
Use INFORMATION_SCHEMA.KEY_COLUMN_USAGE to filter by constraint_type='PRIMARY KEY'.
No. DESCRIBE shows table structure; EXPLAIN shows how the optimizer will execute a SELECT query.
Run mysqldump -d -u user -p ecommerce > schema.sql
; the -d flag omits data.