Skip to content

Instantly share code, notes, and snippets.

@jahid32
Forked from ajaxray/dokan.sql
Created December 4, 2023 18:24
Show Gist options
  • Save jahid32/1b02bfe4e9a34806a0b7c80f8e985234 to your computer and use it in GitHub Desktop.
Save jahid32/1b02bfe4e9a34806a0b7c80f8e985234 to your computer and use it in GitHub Desktop.
[Database Course] Sample schema
CREATE DATABASE `dokan`;
USE `dokan`;
CREATE TABLE customers (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100),
phone CHAR(15),
PASSWORD CHAR(32),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE orders (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
customer_id INT UNSIGNED NOT NULL,
date DATETIME DEFAULT CURRENT_TIMESTAMP,
total_amount DECIMAL (10, 2) NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers (id)
);
CREATE TABLE categories (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
parent_id INT UNSIGNED,
FOREIGN KEY (parent_id) REFERENCES categories (id)
);
CREATE TABLE products (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
category_id INT UNSIGNED,
price DECIMAL (10, 2) UNSIGNED NOT NULL,
stock_quantity INT NOT NULL DEFAULT 0,
weight DECIMAL (5, 2) UNSIGNED,
dimensions VARCHAR(50),
image_url VARCHAR(2083),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories (id)
);
CREATE TABLE order_items (
order_id INT UNSIGNED NOT NULL,
product_id INT UNSIGNED NOT NULL,
quantity INT NOT NULL,
price DECIMAL (10, 2) UNSIGNED NOT NULL,
PRIMARY KEY (order_id, product_id),
FOREIGN KEY (order_id) REFERENCES orders (id),
FOREIGN KEY (product_id) REFERENCES products (id)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment