---
# System prepended metadata

title: 'Session Three: It''s always time to restart | Banco de Dados'

---

# Session Three: It's always time to restart | Banco de Dados
>[color=red]**Autor:** Letícia Rodrigues da Silva
**Turma:** IndoD 
**Número:** 25

[toc]

## Script create table 
```sql=
CREATE TABLE tb_categoria (
  id_categoria		INT PRIMARY KEY AUTO_INCREMENT,
  nm_categoria		VARCHAR(200)
  );
  
CREATE TABLE tb_produto (
    id_ptoduto		INT PRIMARY key AUTO_INCREMENT,
    id_categoria	INT,
    nm_produto      VARCHAR(200),
    vl_preco		DECIMAL(10,2)
    );
    
    
CREATE TABLE tb_estoque (
      id_estoque	 INT primary key AUTO_INCREMENT,
      id_produto	 INT,
      qtd_minima	 INT,
      qtd_disponivel INT
      );
      
CREATE TABLE tb_endereco (
        id_endereco		INT PRIMARY key AUTO_INCREMENT,
        ds_cep			VARCHAR(200),
        ds_endereco		VARCHAR(200),
        nr_endereco		VARCHAR(200),
        ds_cidade		VARCHAR(200)
        );
        
CREATE TABLE tb_cliente (
          id_cliente		INT PRIMARY key AUTO_INCREMENT,
          nm_cliente		VARCHAR(200),
          ds_cpf			VARCHAR(200),
          id_endereco		INT
          );
          
             
CREATE TABLE tb_venda (
          id_venda				INT PRIMARY key AUTO_INCREMENT,
          id_cliente			INT,
          ds_nota_fiscal		VARCHAR(200),
          tp_forma_pagamento	VARCHAR(200),
          qtd_parcelas			INT,
    	  dt_venda				DATETIME,
          id_endereco_entrega	INT 
          );
        
CREATE TABLE tb_venda_item (
        id_venda_item	INT primary key AUTO_INCREMENT,
        id_venda		INT,
        id_produto		INT
        );
```

## Script insert into
```sql=
iNSERT INTO tb_categoria (nm_categoria)
VALUES ("Eletrodoméstico"),
	   ("Moda"),
       ("Eletrônicos"),
       ("Alimentos"),
       ("Assessórios de cozinha"),
  	   ("Brinquedos"),
       ("Saúde"),
       ("Joias"),
       ("Acessórios"),
       ("Livros"),
       ("Bebibas");
       
 
 INSERT INTO tb_produto (id_categoria, nm_produto, vl_preco)
 VALUES (4, "Fini", 4.99),
	    (1, "Microondas", 699.00),
        (10, "It: A coisa", 99.79),
        (3, "Smartphone Samsung Galaxy S20", 2249.99),
        (3, "Smart TV LED 32 Samsung", 1424.99),
  	    (6, "Barbie com Bicicleta Ftv96", 124.99),
        (9, "Cadeira De Alumínio Reclinável", 275.90),
        (7, "Creme Dental Oral B Pro", 17.99),
        (2, "Blusa Moletom Casaco Unissex Harry Potter", 155.99),
        (2, "Tênis Vans Old Skool Unissex", 148.90),
        (5, "Conjunto de Potes Herméticos", 79.99),
        (8, "Anel Falange Prateado Jóias", 34.44),
        (8, "Anel Falange Prateado Jóias", 34.44),
        (11, "RedBull", 6.99),
        (4, "Pipoca Pronta Doce Caramelizada", 7.19),
        (1, "Geladeira Consul Frost Free Duplex", 3099.00),
        (3, "Notebook Acer Aspire", 3999.00),
        (3, "Capinha iphone 5s/5c/5", 24.99),
        (1, "Máquina De Algodão Doce", 274.41),
        (1, "Máscara Descartável Triplas - 100 Unidades", 40.00);
        
        
   INSERT INTO tb_estoque (id_produto, qtd_minima, qtd_disponivel)
   VALUES (1, 1, 800),
   		  (2, 1, 1000),
          (3, 1, 950),
          (4, 1, 2000),
          (4, 1, 2500),
          (6, 1, 1800),
          (7, 1, 700),
          (8, 1, 1000),
          (9, 1, 3100),
          (10, 1, 850),
          (11, 1, 3000),
          (12, 1, 700),
          (13, 1, 9800),
          (14, 1, 2800),
          (15, 1, 5600),
          (16, 1, 900),
          (17, 1, 400),
          (18, 1, 1300),
          (19, 1, 500),
          (20, 1, 300);
          
          
 INSERT INTO tb_endereco (ds_cep, ds_endereco, nr_endereco, ds_cidade)
 VALUES ("19061-265", "Rua Francisco Clélis", "532", "São Paulo"),
 		("06530-2105", "Avenida João Marques Nogueira", "145", "São Paulo"),
        ("05888-170", "Rua das Goiabeiras", "433", "São Paulo"),
        ("6020-275", "Passagem Filósofo Karl Marx", "860", "São Paulo"),
        ("6020-275", "Rua Luiz Gonzaga Vieira de Andrade", "545", "São Paulo"),
        ("12945-850", "Rua Venezuela", "756", "São Paulo"),
        ("09931-466", "Rua dos Bandeirantes", "162", "São Paulo"),
        ("14406-750", "Rua Irene de Souza Spera", "892", "São Paulo"),
        ("06502-290", "Rua Padre Celestino", "996", "São Paulo"),
        ("13610-639", "Rua Trêss", "244", "São Paulo"),
        ("19816-104", "Praça Napoleão Laureano", "297", "São Paulo"),
        ("07013-10", "Rua Epitácio Pessoa", "508", "São Paulo"),
        ("17022-143", "Rua Geraldo Bento dos Santos", "353", "São Paulo"),
        ("11370-600", "Rua Soldado José Alves de Abreu", "250", "São Paulo"),
        ("09572-320", "Rua Nelson Hemenegildo", "657", "São Paulo"),
        ("09572-320", "Rua Modesto Junqueira", "922", "São Paulo"),
        ("12280-043", "Rua Josephina Capuano Chequer", "542", "São Paulo"),
        ("17604-530", "Rua Isabel Assis Barbosa", "933", "São Paulo"),
        ("14076-120", "Rua Hermínio Francischetti", "491", "São Paulo"),
        ("19908-306", "Rua Sete", "402", "São Paulo"),
        ("13418-370", "Rua Rodolfo Devide", "423", "São Paulo"),
        ("13486-322", "Rua Dona Gemma Carvalho Alcântaras", "916", "São Paulo"),
        ("13059-435", "Rua Doutor Gilberto Sil", "583", "São Paulo"),
        ("07050-100", "Rua Felipe Chiedde", "631", "São Paulo"),
        ("6901-1030", "Rua Iguassu", "631", "São Paulo");
        
        
        
INSERT INTO tb_cliente (nm_cliente, ds_cpf, id_endereco)
VALUES ("Gabriela Carolina Pereira", "419.926.368-34", 17),
        	   ("Marlene Malu Emily dos Santos", "093.203.098-09", 2),
               ("Luana Heloisa Nogueira", "093.772.018-61", 12),
               ("Josefa Mariane Fernandes", "887.851.468-38", 4),
               ("Natália Emanuelly Bernardes", "343.774.598-05", 24),
               ("Esther Lúcia Aparecida Novaes", "417.218.228-36", 9),
               ("Sarah Maitê Elza Novaes", "378.690.498-75", 15),
               ("Daniela Sarah Vitória Rezende", "660.039.258-41", 1),
               ("Aparecida Emanuelly Nicole Corte Real", "509.472.468-19", 7),
               ("Maria Nina Cardoso", "835.201.168-55", 3),
               ("Lúcia Andreia Juliana da Mata", "076.247.398-36", 25),
               ("Marlene Fátima Lívia Moreira", "619.491.478-51", 6),
               ("Alícia Julia Nina Mendes", "635.741.458-10", 5),
               ("Giovana Sophia Sophie da Rocha", "903.909.758-50", 13),
               ("Isabelle Stefany Rocha", "722.665.828-36", 11),
               ("Regina Alícia Eloá da Silva", "419.926.368-34", 18),
               ("Débora Patrícia Farias", "428.446.767-4", 20),
               ("Heloisa Milena Sophia dos Santos", "339.383.578-51", 14),
               ("Evelyn Rebeca da Luz", "309.974.728-98", 19),
               ("Elaine Isis Ribeiro", "947.567.058-04", 16),
               ("Valentina Sophia Sophia Assis", "918.611.848-08", 22),
               ("Andrea Laís Jesus", "721.448.688-16", 8),
               ("Lara Carla Campos", "308.938.278-43", 10),
               ("Débora Eduarda Gonçalves", "573.259.198-24", 21),
               ("Andrea Marcela Gabriela Rezende", "985.474.688-70", 23);
               
               
INSERT INTO tb_venda (id_cliente, ds_nota_fiscal, tp_forma_pagamento, qtd_parcelas, dt_venda, id_endereco_entrega)
VALUES (1, "Digital", "Débito", 2, '2021-10-03', 2),
 	   (2, "Física", "Crédito", 1, '2021-5-01', 4),
       (3, "Física", "Débito", 5, '2021-01-25', 10),
       (4, "Digital", "Crédito", 3, '2021-10-02', 10),
       (5, "Física", "Crédito", 4, '2021-03-28', 1),
       (6, "Digital", "Débito", 3, '2021-04-30', 7),
       (7, "Digital", "Crédito", 2, '2021-12-04', 8),
       (8, "Digital", "Débito", 1, '2021-05-05', 4),
 	   (9, "Física", "Débito", 6, '2021-05-20', 9),
       (10, "Digital", "Débito", 2, '2021-10-03', 15),
       (11, "Digital", "Crédito", 5, '2021-10-03', 19),
       (12, "Digital", "Crédito", 3, '2021-10-03', 9),
       (13, "Física", "Débito", 2, '2021-10-03', 25),
       (14, "Digital", "Crédito", 7, '2021-10-03', 20),
       (15, "Física", "Débito", 3, '2021-10-03', 15),
       (16, "Física", "Débito", 2, '2021-10-03', 3),
       (17, "Física", "Crédito", 1, '2021-10-03', 5),
       (18, "Digital", "Débito", 9, '2021-10-03', 10),
       (19, "Física", "Crédito", 2, '2021-10-03', 12),
       (20, "Digital", "Débito", 2, '2021-10-03', 20),
       (21, "Digital", "Débito", 1, '2021-10-03', 23),
       (22, "Digital", "Crédito", 5, '2021-10-03', 6),
       (23, "Física", "Crédito", 10, '2021-10-03', 11),
       (24, "Física", "Débito", 8, '2021-10-03', 14),
       (25, "Física", "Débito", 1, '2021-10-03', 16),
       (26, "Digital", "Crédito", 3, '2021-10-03', 18),
       (27, "Digital", "Débito", 9, '2021-10-03', 20),
       (28, "Física", "Débito", 2, '2021-10-03', 13),
       (29, "Digital", "Crédito", 4, '2021-10-03', 21),
       (30, "Física", "Débito", 1, '2021-10-03', 21);
       
       
    
INSERT INTO tb_venda_item(id_venda, id_produto)
VALUES (1, 20),
       (1, 11),
       (2, 4),
       (5, 6),
       (5, 3),
       (6, 19),
       (7, 16),
       (7, 2),
       (8, 1),
       (8, 15),
       (8, 8),
       (9, 10),
       (9, 9),
       (10, 17),
       (10, 20),
       (11, 14),
       (12, 11),
       (12, 3),
       (13, 7),
       (14, 5),
       (14, 6),
       (14, 1),
       (15, 3),
       (16, 6),
       (17, 17),
       (17, 18),
       (18, 19),
       (15, 3),
       (15, 7),
       (19, 12),
       (19, 4),
       (20, 17),
       (21, 11),
       (21, 8),
       (22, 9),
       (23, 3),
       (23, 15),
       (25, 18),
       (25, 17),
       (26, 6),
       (26, 3),
       (27, 9),
       (27, 12),
       (27, 1),
       (28, 4),
       (29, 19),
       (29, 6),
       (29, 1),
       (30, 5),
       (30, 4);
```
