-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoreManager.sql
46 lines (37 loc) · 1.05 KB
/
StoreManager.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
36
37
38
39
40
41
42
43
44
45
46
DROP DATABASE IF EXISTS StoreManager;
CREATE DATABASE StoreManager;
USE StoreManager;
CREATE TABLE products (
id INT NOT NULL auto_increment,
name VARCHAR(30) NOT NULL,
quantity INT NOT NULL,
PRIMARY KEY(id)
) ENGINE=INNODB;
CREATE TABLE sales (
id INT NOT NULL auto_increment,
date DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
) ENGINE=INNODB;
CREATE TABLE sales_products (
sale_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
FOREIGN KEY (sale_id)
REFERENCES sales (id)
ON DELETE CASCADE,
FOREIGN KEY (product_id)
REFERENCES products (id)
ON DELETE CASCADE
) ENGINE=INNODB;
SET SQL_SAFE_UPDATES = 0;
INSERT INTO StoreManager.products (name, quantity) VALUES
("Martelo de Thor", 10),
("Traje de encolhimento", 20),
("Escudo do Capitão América", 30);
INSERT INTO StoreManager.sales (date) VALUES
(NOW()),
(NOW());
INSERT INTO StoreManager.sales_products (sale_id, product_id, quantity) VALUES
(1, 1, 5),
(1, 2, 10),
(2, 3, 15);