-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script Banco Biblitoeca .txt
93 lines (82 loc) · 2.77 KB
/
Script Banco Biblitoeca .txt
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
CREATE DATABASE BIBLIOTECA;
USE BIBLIOTECA;
-- Tabela de Tipos de Usuários
CREATE TABLE TiposDeUsuarios (
TipoUsuarioID INT PRIMARY KEY,
Nome VARCHAR(50) NOT NULL
);
-- Tabela de Usuários
CREATE TABLE Usuarios (
UsuarioID INT PRIMARY KEY,
Nome VARCHAR(100) NOT NULL,
TipoUsuarioID INT,
FOREIGN KEY (TipoUsuarioID) REFERENCES TiposDeUsuarios(TipoUsuarioID)
);
-- Tabela de Livros
CREATE TABLE Livros (
LivroID INT PRIMARY KEY,
Titulo VARCHAR(255) NOT NULL,
Autor VARCHAR(100) NOT NULL,
AnoPublicacao INT,
Disponivel BOOLEAN NOT NULL
);
-- Tabela de Empréstimos
CREATE TABLE Emprestimos (
EmprestimoID INT PRIMARY KEY,
UsuarioID INT,
LivroID INT,
DataEmprestimo DATE NOT NULL,
DataDevolucaoPrevista DATE NOT NULL,
FOREIGN KEY (UsuarioID) REFERENCES Usuarios(UsuarioID),
FOREIGN KEY (LivroID) REFERENCES Livros(LivroID)
);
-- Tabela de Devoluções
CREATE TABLE Devolucoes (
DevolucaoID INT PRIMARY KEY,
EmprestimoID INT,
DataDevolucao DATE NOT NULL,
Penalidade DECIMAL(10, 2),
FOREIGN KEY (EmprestimoID) REFERENCES Emprestimos(EmprestimoID)
);
-- Inserindo dados
-- Inserir registros na tabela TiposDeUsuarios
INSERT INTO TiposDeUsuarios (TipoUsuarioID, Nome)
VALUES
(1, 'Estudante'),
(2, 'Professor'),
(3, 'Funcionário'),
(4, 'Visitante'),
(5, 'Bibliotecário');
-- Inserir registros na tabela Usuarios
INSERT INTO Usuarios (UsuarioID, Nome, TipoUsuarioID)
VALUES
(1, 'João Silva', 1),
(2, 'Maria Santos', 2),
(3, 'Pedro Alves', 1),
(4, 'Ana Pereira', 3),
(5, 'Lucas Oliveira', 4);
-- Inserir registros na tabela Livros
INSERT INTO Livros (LivroID, Titulo, Autor, AnoPublicacao, Disponivel)
VALUES
(1, 'Dom Casmurro', 'Machado de Assis', 1899, true),
(2, 'A Revolução dos Bichos', 'George Orwell', 1945, true),
(3, 'Cem Anos de Solidão', 'Gabriel García Márquez', 1967, true),
(4, 'O Senhor dos Anéis', 'J.R.R. Tolkien', 1954, true),
(5, 'Harry Potter e a Pedra Filosofal', 'J.K. Rowling', 1997, true);
-- Inserir registros na tabela Emprestimos
INSERT INTO Emprestimos (EmprestimoID, UsuarioID, LivroID, DataEmprestimo, DataDevolucaoPrevista)
VALUES
(1, 1, 2, '2023-08-15', '2023-09-15'),
(2, 3, 1, '2023-08-20', '2023-09-20'),
(3, 2, 4, '2023-08-25', '2023-09-25'),
(4, 4, 3, '2023-08-30', '2023-09-30'),
(5, 5, 5, '2023-09-01', '2023-10-01');
-- Inserir registros na tabela Devolucoes
INSERT INTO Devolucoes (DevolucaoID, EmprestimoID, DataDevolucao, Penalidade)
VALUES
(1, 1, '2023-09-16', 0.00),
(2, 2, '2023-09-21', 0.00),
(3, 3, '2023-09-28', 0.00),
(4, 4, '2023-10-05', 0.00),
(5, 5, '2023-10-02', 0.00);
-- Retornando dados