Code Examples
-- One-to-Many: one customer has many orders
CREATE TABLE customers (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE
);
CREATE TABLE orders (
id INT PRIMARY KEY AUTO_INCREMENT,
custo...
-- One user has one profile (optional extension table)
CREATE TABLE user_profiles (
user_id INT PRIMARY KEY, -- same as users.id
bio TEXT,
avatar_url VARCHAR(300),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);