-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.sql
More file actions
75 lines (65 loc) · 2.21 KB
/
Copy pathsql.sql
File metadata and controls
75 lines (65 loc) · 2.21 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
create database if not exists biblioteca;
use biblioteca;
create table if not exists `usuario` (
id int auto_increment primary key,
nome varchar(255) not null,
login varchar(255) unique not null,
senha varchar(255) not null,
tipo_usuario varchar(255) not null
);
create table if not exists `leitor` (
id int auto_increment primary key,
usuario_id int not null,
telefone varchar(255) unique not null,
endereco varchar(255) unique not null,
foreign key (usuario_id) references `usuario`(id) on delete cascade
);
create table if not exists `fornecedor` (
id int auto_increment primary key,
nome varchar(255) not null,
cnpj varchar(255) unique not null,
telefone varchar(255) unique not null
);
create table if not exists `livro` (
id int auto_increment primary key,
titulo varchar(255) not null,
autor varchar(255) not null,
editora varchar(255) not null,
data_publicacao date not null,
genero varchar(255) not null,
fornecedor_id int not null,
quantidade int not null,
foreign key (fornecedor_id) references fornecedor(id)
);
create table if not exists `emprestimo` (
id int auto_increment primary key,
leitor_id int not null,
livro_id int not null,
data_emprestimo timestamp default current_timestamp,
data_devolucao date not null,
foreign key (leitor_id) references leitor(id),
foreign key (livro_id) references livro(id)
);
create table if not exists `fornecimento` (
id int auto_increment primary key,
fornecedor_id int not null,
livro_id int not null,
foreign key (fornecedor_id) references fornecedor(id),
foreign key (livro_id) references livro(id)
);
create table if not exists `reserva` (
id int auto_increment primary key,
leitor_id int not null,
livro_id int not null,
data_reserva timestamp default current_timestamp,
foreign key (leitor_id) references leitor(id),
foreign key (livro_id) references livro(id)
);
create table if not exists `devolucao` (
id int auto_increment primary key,
leitor_id int not null,
livro_id int not null,
data_devolucao timestamp default current_timestamp,
foreign key (leitor_id) references leitor(id),
foreign key (livro_id) references livro(id)
);