-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackupDB.sql
More file actions
52 lines (43 loc) · 923 Bytes
/
backupDB.sql
File metadata and controls
52 lines (43 loc) · 923 Bytes
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
47
48
49
50
51
52
DROP DATABASE IF EXISTS StoreManager;
CREATE DATABASE StoreManager;
USE StoreManager;
CREATE TABLE products (
id INT NOT NULL auto_increment,
name VARCHAR(30) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE sales (
id INT NOT NULL auto_increment,
date DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
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
);
SET
SQL_SAFE_UPDATES = 0;
INSERT INTO
StoreManager.products (name)
VALUES
("Bolsa"),
("Casaco"),
("Tenis"),
("Bota");
INSERT INTO
StoreManager.sales (date)
VALUES
(NOW()),
(NOW()),
(NOW());
INSERT INTO
StoreManager.sales_products (sale_id, product_id, quantity)
VALUES
(1, 1, 5),
(1, 2, 10),
(2, 3, 15),
(3, 4, 3),
(3, 1, 4);