-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbancodedados.sql
More file actions
59 lines (59 loc) · 2.16 KB
/
bancodedados.sql
File metadata and controls
59 lines (59 loc) · 2.16 KB
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
create database if not exists Farm;
use Farm;
create table if not exists Propriedades (
numero_de_escritura int not null,
nome varchar(20) not null,
tamanho float not null,
primary key(numero_de_escritura)
);
create table if not exists Localizacao (
id_localizacao int not null AUTO_INCREMENT,
cidade VARCHAR(20) not null,
estado VARCHAR(20) not null,
lagradouro VARCHAR(45) not null,
ponto_de_referencia VARCHAR(45) not null,
numero_de_escritura_propriedade int not null,
primary key (id_localizacao),
foreign key(numero_de_escritura_propriedade) references Propriedades(numero_de_escritura) ON UPDATE CASCADE ON DELETE CASCADE
);
create table if not exists Plantacoes (
id_plantacao int not null AUTO_INCREMENT,
apelido VARCHAR(20) not null,
tamanho float not null,
data_de_plantio date not null,
numero_de_escritura_propriedade int not null,
primary key(id_plantacao),
foreign key(numero_de_escritura_propriedade) references Propriedades(numero_de_escritura) ON UPDATE CASCADE ON DELETE CASCADE
);
create table if not exists Cultura (
nome varchar(30) not null,
especie varchar(30) not null,
classificacao varchar(30) not null,
plantacao_id int not null,
primary key(nome),
foreign key(plantacao_id) references Plantacoes(id_plantacao) ON UPDATE CASCADE ON DELETE CASCADE
);
create table if not exists Atividades(
id_atividade int not null AUTO_INCREMENT,
data date not null,
valor float,
plantacao_id int not null,
descricao varchar(100) not null,
primary key (id_atividade),
foreign key(plantacao_id) references Plantacoes(id_plantacao) ON UPDATE CASCADE ON DELETE CASCADE
);
create table if not exists Colheitas(
id_colheita int not null AUTO_INCREMENT,
valor_ganho float not null,
atividade_id int not null,
primary key(id_colheita),
foreign key(atividade_id) references Atividades(id_atividade) ON UPDATE CASCADE ON DELETE CASCADE
);
create table if not exists Quantidade (
id_quantidade int not null AUTO_INCREMENT,
tipo varchar(10) not null,
valor int not null,
colheita_id int not null,
primary key(id_quantidade),
foreign key(colheita_id) REFERENCES Colheitas(id_colheita) ON UPDATE CASCADE ON DELETE CASCADE
);