-
Notifications
You must be signed in to change notification settings - Fork 1
/
script_database.sql
70 lines (64 loc) · 1.72 KB
/
script_database.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
CREATE DATABASE IF NOT EXISTS `smarket`;
USE `smarket`;
CREATE TABLE IF NOT EXISTS `clients` (
`NUM_PED` int PRIMARY KEY,
`DATA` date NOT NULL,
`COD_CLI` int NOT NULL,
`CLIENTE` varchar(50) NOT NULL,
`ENDERECO` varchar(75) NOT NULL,
`RG` varchar(11) NOT NULL,
`TOTAL_GERAL` float NOT NULL
);
CREATE TABLE IF NOT EXISTS `orders` (
`NUM_PED` int REFERENCES `clients` (`NUM_PED`),
`COD_PROD` int NOT NULL,
`DESCRICAO` varchar(75) NOT NULL,
`QUANT` int NOT NULL,
`PRECO` float NOT NULL,
`TOTAL` float as (`QUANT` * `PRECO`),
`TOTAL_GERAL` float NOT NULL,
UNIQUE(`COD_PROD`)
);
INSERT INTO
`clients`
VALUES
(
00002,
STR_TO_DATE("05/09/11", "%d/%m/%y"),
10,
"MARLA",
"RUA DOS CACTOS, 27",
"1.159.719",
303.80
),
(
00005,
STR_TO_DATE("01/09/11", "%d/%m/%y"),
12,
"KEYLA",
"RUA DO JUÁ, 34",
"1.120.702",
180.80
);
INSERT INTO
`orders` (
NUM_PED,
COD_PROD,
DESCRICAO,
QUANT,
PRECO,
TOTAL_GERAL
)
VALUES
(00002, 0010, "BISCOITO MARIA", 10, 1.30, 303.80),
(00002, 0011, "CUZCUZ VITAMILHO", 18, 1.00, 303.80),
(00002, 0014, "CHARQUE PONTA", 15, 7.00, 303.80),
(00002, 0015, "ARROZ TIO JOÃO", 20, 2.00, 303.80),
(00002, 0016, "FEIJAO KERO-KERO", 30, 3.50, 303.80),
(00002, 0017, "FARINHA BREJEIRA", 12, 1.90, 303.80),
(00005, 0010, "BISCOITO MARIA", 10, 1.30, 180.80),
(00005, 0015, "ARROZ TIO JOÃO", 20, 2.00, 180.80),
(00005, 0016, "FEIJAO KERO-KERO", 30, 3.50, 180.80),
(00005, 0017, "FARINHA BREJEIRA", 12, 1.90, 180.80);
SELECT* FROM `clients`;
SELECT * FROM `orders`;