-- atividade sql 2
create table livros(
    id_livro integer(20) primary key not null,
    titulo varchar(100) not null,
    autor varchar (100) not null,
    ano_publicacao integer(4) not null
);

create table clientes(
    id_cliente integer(20) primary key not null,
    nome varchar (100) not null,
    email varchar (100) not null unique,
    telefone varchar(15) not null unique
);

create table emprestimos(
    id_emprestimo integer (20) primary key not null,
    id_cliente integer,
    id_livro integer,
    data_emprestimo date (8) not null,
    data_devolucao date (8) not null,
    constraint fk_emprestimocliente foreign key (id_cliente) references clientes (id_cliente),
    constraint fk_emprestimolivro foreign key (id_livro) references livros (id_livro)
);

INSERT INTO livros (id_livro, titulo, autor, ano_publicacao)
VALUES
    (1, 'Dom Casmurro', 'Machado de Assis', 1899),
    (2, 'O Cortiço', 'Aluísio Azevedo', 1890),
    (3, 'Memórias Póstumas de Brás Cubas', 'Machado de Assis', 1881),
    (4, 'Capitães da Areia', 'Jorge Amado', 1937),
    (5, 'Grande Sertão: Veredas', 'Guimarães Rosa', 1956);

INSERT INTO clientes (id_cliente, nome, email, telefone) 
VALUES
    (1, 'Carlos Silva', 'carlos.silva@gmail.com', '11999999999'),
    (2, 'Maria Santos', 'maria.santos@gmail.com', '21988888888'),
    (3, 'João Pereira', 'joao.pereira@gmail.com', '31977777777'),
    (4, 'Ana Souza', 'ana.souza@gmail.com', '41966666666'),
    (5, 'Paulo Oliveira', 'paulo.oliveira@gmail.com', '51955555555');

INSERT INTO emprestimos (id_emprestimo, id_cliente, id_livro, data_emprestimo, data_devolucao) 
VALUES
    (1, 1, 1, '2025-01-01', '2025-03-10'),
    (2, 2, 2, '2018-12-03', '2019-05-12'),
    (3, 3, 3, '2024-06-05', '2024-07-15'),
    (4, 4, 4, '2023-01-07', '2023-01-17'),
    (5, 5, 5, '2021-12-09', '2022-03-19');

select * from clientes;
select * from livros where ano_publicacao > 1950;
select * from emprestimos where data_emprestimo >= '2023-01-01' and data_emprestimo <= '2023-12-31';
update clientes set telefone = '2196234124324' where id_cliente = 2;
delete from livros where id_livro = 5;
select * from clientes;
select * from livros;
































Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: