Created
November 17, 2023 14:50
-
-
Save ajaxray/05de489f214fabbfd0c5b775e988f255 to your computer and use it in GitHub Desktop.
[Database Course] Sample schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Random Sample Data