This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script-criacao-tabelas-aquario-e-medida.sql
166 lines (149 loc) · 6.62 KB
/
script-criacao-tabelas-aquario-e-medida.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
create database hop_tech;
use hop_tech;
create table empresa_cliente(
idEmpresa int primary key auto_increment,
nomeEmpresa varchar(50) not null,
cnpj char(18) not null,
emailEmpresa varchar(100) not null,
estadoEmpresa varchar(50) not null,
cidadeEmpresa varchar(50) not null,
cepEmpresa char(9) not null,
bairroEmpresa varchar(50) not null,
ruaEmpresa varchar(50) not null,
numeroEmpresa int not null,
complementoEmpresa varchar(100),
responsavelEmpresa varchar(50) not null
);
create table telefone_empresa(
idTelefone int primary key auto_increment,
telefone varchar(15) not null,
fkEmpresa int, foreign key (fkEmpresa) references empresa_cliente(idEmpresa)
);
create table usuario(
idUsuario int primary key auto_increment,
tipoUsuario int, constraint chkTpUsuario check (tipoUsuario in (0, 1)),
usuario varchar(45) not null,
senha varchar(45) not null,
fkEmpresa int, foreign key(fkEmpresa) references empresa_cliente(idEmpresa)
);
create table lupulo(
idLupulo int primary key auto_increment,
tipoLupulo varchar(45) not null,
qtdHrsIdealLuz float
);
create table plantacao(
idPlantacao int primary key auto_increment,
tipoIluminacao varchar(45) not null, constraint chkTpIluminacao check (tipoIluminacao in('Natural', 'Artificial')),
metroQuadradoPlantacao float not null,
regiaoPlantacao varchar(45) not null,
estadoPlantacao varchar(45) not null,
cidadePlantacao varchar(45) not null,
fkLupulo int not null, foreign key (fkLupulo) references lupulo(idLupulo),
fkEmpresa int not null, foreign key (fkEmpresa) references empresa_cliente(idEmpresa)
);
create table sensor(
idSensor int primary key auto_increment,
tipoSensor varchar(45) not null, constraint chkTpSensor check (tipoSensor in('Luminosidade')),
statusSensor varchar(45) not null, constraint chkStatusSensor check (statusSensor in('Ativo', 'Inativo', 'Em manutenção')),
fkPlantacao int not null, foreign key (fkPlantacao) references plantacao(idPlantacao),
regiaoSensor varchar(45), constraint chkRegiaoSensor check (regiaoSensor in ('Norte', 'Nordeste', 'Centro-Oeste', 'Suldeste', 'Sul'))
);
create table capturaLuminosidade(
idCaptura int primary key auto_increment,
dtCaptura date not null,
hrCaptura time not null,
luminosidade float not null,
fkSensor int, foreign key (fkSensor) references sensor(idSensor)
);
use hop_tech;
-- Inserção de dados mocados
insert into empresa_cliente values
(null, 'LupAgro', '70.357.617/0001-44', 'lupagro@outlook.com.br', 'RS', 'Pelotas', '96090-710', 'Laranjal', 'Rua São Lourenço do Sul', '810', 'Area rural, ao lado de uma plantação de lupulo.', 'Igor Ferreira'),
(null, 'Lupulo Ltda', '59.484.892/0001-96', 'lupuloltda@outlook.com.br', 'AM', 'Manaus', '69023-490', 'Tarumã-Açu', 'Ramal do Mariano', '1498', null, 'Ayla Teys'),
(null, 'LAL Agro Malte ', '89.422.803/0001-48', 'lal@outlook.com.br', 'MT', 'Cuiabá', '78065-150', 'Jardim Tropical', 'Rua Varsóvia', '222', null, 'Alicia Nizis');
insert into telefone_empresa values
(null, '(53) 2814-7384', 1),
(null, '(53) 99374-9980', 1),
(null, '(92) 3876-9475', 2),
(null, '(65) 3578-5674', 3);
insert into usuario values
(null, 0, 'hoppers', '123', null),
(null, 1, 'LupAgroAdmin', '4321', 1),
(null, 1, 'LupuloLtdaAdmin', '5678', 2),
(null, 1, 'LalAdmin', '0987', 3);
insert into lupulo values
(null, 'Admiral', 15),
(null, 'Ahtanum', 15),
(null, 'Amarillo', 15);
insert into plantacao values
(null, 'Natural', 1000, 'Sul', 'RS', 'Pelotas', 2, 1),
(null, 'Natural', 10000, 'Norte', 'AM', 'Manaus', 1, 2),
(null, 'artificial', 5500, 'Centro-Oeste', 'MT', 'Cuiabá', 3, 3);
insert into sensor values
(null, 'Luminosidade', 'Ativo', 1, 'Norte'),
(null, 'Luminosidade', 'Ativo', 1, 'Nordeste'),
(null, 'Luminosidade', 'Em manutenção', 1, 'Centro-Oeste'),
(null, 'Luminosidade', 'Ativo', 1, 'Suldeste'),
(null, 'Luminosidade', 'Ativo', 1, 'Sul'),
(null, 'Luminosidade', 'Ativo', 2, 'Norte'),
(null, 'Luminosidade', 'Ativo', 2, 'Nordeste'),
(null, 'Luminosidade', 'Ativo', 2, 'Centro-Oeste'),
(null, 'Luminosidade', 'Ativo', 2, 'Suldeste'),
(null, 'Luminosidade', 'Ativo', 2, 'Sul'),
(null, 'Luminosidade', 'Ativo', 3, 'Norte'),
(null, 'Luminosidade', 'Ativo', 3, 'Nordeste'),
(null, 'Luminosidade', 'Ativo', 3, 'Centro-Oeste'),
(null, 'Luminosidade', 'Ativo', 3, 'Suldeste'),
(null, 'Luminosidade', 'Ativo', 3, 'Sul');
insert into capturaLuminosidade values
(null, '2023-04-01', '10:00:00', 350, 1),
(null, '2023-04-01', '10:00:00', 350, 2),
(null, '2023-04-01', '10:00:00', 520, 3),
(null, '2023-04-01', '10:00:00', 550, 4),
(null, '2023-04-01', '10:00:00', 550, 5),
(null, '2023-04-01', '10:00:00', 575, 6),
(null, '2023-04-01', '10:00:00', 578, 7),
(null, '2023-04-01', '10:00:00', 645, 8),
(null, '2023-04-01', '10:00:00', 576, 9),
(null, '2023-04-01', '10:00:00', 574, 10),
(null, '2023-04-01', '10:00:00', 700, 11),
(null, '2023-04-01', '10:00:00', 701, 12),
(null, '2023-04-01', '10:00:00', 659, 13),
(null, '2023-04-01', '10:00:00', 500, 14),
(null, '2023-04-01', '10:00:00', 505, 15),
(null, '2023-04-01', '10:30:00', 467, 1),
(null, '2023-04-01', '10:30:00', 128, 2),
(null, '2023-04-01', '10:30:00', 520, 3),
(null, '2023-04-01', '10:30:00', 550, 4),
(null, '2023-04-01', '10:30:00', 550, 5),
(null, '2023-04-01', '10:30:00', 575, 6),
(null, '2023-04-01', '10:30:00', 578, 7),
(null, '2023-04-01', '10:30:00', 645, 8),
(null, '2023-04-01', '10:30:00', 572, 9),
(null, '2023-04-01', '10:30:00', 570, 10),
(null, '2023-04-01', '10:30:00', 705, 11),
(null, '2023-04-01', '10:30:00', 702, 12),
(null, '2023-04-01', '10:30:00', 659, 13),
(null, '2023-04-01', '10:30:00', 479, 14),
(null, '2023-04-01', '10:30:00', 505, 15);
-- Consulta de dados
select * from empresa_cliente;
select * from telefone_empresa;
select * from usuario;
select * from lupulo;
select * from sensor;
select * from plantacao;
select * from capturaLuminosidade;
select date_format(capturaLuminosidade.dtCaptura, '%d/%m/%Y') as 'Data',
capturaLuminosidade.hrCaptura as Hora,
capturaLuminosidade.luminosidade as 'Luminosidade Recebida',
sensor.regiaoSensor as 'Região da Plantação',
lupulo.tipoLupulo as 'Lupulo',
empresa_cliente.nomeEmpresa as 'Empresa Responsável'
from capturaLuminosidade
join sensor on idSensor = fkSensor
join plantacao on idPlantacao = fkPlantacao
join lupulo on idLupulo = fkLupulo
join empresa_cliente on idEmpresa = fkEmpresa
where luminosidade < 500
order by luminosidade;