
Simple MySQL example for E-commice
Hi everyone, I wanted to share my experience with SQL. In this post, I’ll walk through some snippets that illustrate what a simple e-commerce schema might look like. `-- Role table CREATE TABLE role ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL UNIQUE, description VARCHAR(255) ); -- Insert default roles INSERT INTO role (name, description) VALUES ('admin', 'Full system access'), ('customer', 'Can browse and place orders'), ('staff', 'Can manage orders and products'), ('vendor', 'Supplier with limited access'); -- User table CREATE TABLE user ( id INT AUTO_INCREMENT PRIMARY KEY, role_id INT NOT NULL, first_name VARCHAR(100) NOT NULL, last_name VARCHAR(100) NOT NULL, email VARCHAR(255) NOT NULL UNIQUE, password_hash VARCHAR(255) NOT NULL, phone VARCHAR(20), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (role_id) REFERENCES role(id) ); -- Producer table (linked to a user) CREATE TABLE producer ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL UNIQUE,
Continue reading on Dev.to
Opens in a new tab




