CREATE TABLE Users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
phone VARCHAR(20)
);
CREATE TABLE Products (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
quantity INT NOT NULL
);
CREATE TABLE Orders (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
order_date DATE NOT NULL,
status ENUM('new', 'in progress', 'completed'
DEFAULT 'new',
FOREIGN KEY (user_id) REFERENCES Users(id)
);
CREATE TABLE OrderItems (
id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
FOREIGN KEY (order_id) REFERENCES Orders(id),
FOREIGN KEY (product_id) REFERENCES Products(id)
);
CREATE TABLE Shipping (
id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT NOT NULL,
address VARCHAR(255) NOT NULL,
city VARCHAR(255) NOT NULL,
country VARCHAR(255) NOT NULL,
postal_code VARCHAR(20) NOT NULL,
FOREIGN KEY (order_id) REFERENCES Orders(id)
);