Lesson 5 / 28
CREATE TABLE
Define a table's columns and their types.
A simple table
List each column with its type, then any table-level options.
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);Inspecting a table
DESCRIBE (or DESC) shows the column list, types and keys without opening a GUI.
DESC customers;
Output:
Field | Type | Null | Key | Default id | int | NO | PRI | NULL name | varchar(100) | NO | | NULL email | varchar(150) | YES | UNI | NULL created_at | datetime | YES | | CURRENT_TIMESTAMP
DROP TABLE is permanent
DROP TABLE customers; deletes the table and all its data instantly — there's no undo without a backup.