-
Notifications
You must be signed in to change notification settings - Fork 0
/
001-order_demo-init.sql
35 lines (32 loc) · 1.03 KB
/
001-order_demo-init.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
CREATE DATABASE IF NOT EXISTS order_demo;
USE order_demo;
# Base table for products.
CREATE TABLE IF NOT EXISTS product (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
name VARCHAR(256) NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (id),
UNIQUE (`name`)
)
ENGINE=InnoDB
;
# Base table for orders.
CREATE TABLE IF NOT EXISTS `order` (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (id)
)
ENGINE=InnoDB
;
# Base table for order items.
CREATE TABLE IF NOT EXISTS order_items (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
order_id INT UNSIGNED NOT NULL,
product_id INT UNSIGNED NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (id),
CONSTRAINT `oi_order_FK` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `oi_product_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
)
ENGINE=InnoDB
;