---
# System prepended metadata

title: 'Session Three: It''s always time to restart'

---

# Session Three: It's always time to restart
Autor: Mateus


[toc]


## create Table


`````sql
   CREATE TABLE        tb_categoria (
     id_categoria      int primary key auto_increment,
     nm_categoria      varchar(100)
     ); 
  
  
  
   CREATE TABLE        tb_produto (
     id_produto        int primary key auto_increment, 
     id_categoria      int, 
     nm_produto        varchar(255), 
     vl_preco          decimal (15,2),
     foreign key       (id_categoria)  REFERENCES  tb_categoria (id_categoria) on delete cascade 
    ); 
  
  
  
  
   CREATE TABLE        tb_estoque (
     id_estoque        int primary key auto_increment, 
     id_produto        int,
     qtd_minima        int, 
     qtd_disponivel    int, 
     foreign key      (id_produto)  REFERENCES  tb_produto (id_produto) on delete cascade
      ); 
  
  
  
    CREATE TABLE      tb_endereco (
      id_endereco     int primary key auto_increment, 
      ds_cep          varchar(100), 
      ds_endereco     varchar(100),
      nr_endereco     varchar(100), 
      ds_cidade       varchar(100)
      ); 
  
  
  
    CREATE TABLE       tb_cliente (
      id_cliente       int primary key auto_increment, 
      nm_cliente       varchar(100), 
      ds_cpf           varchar(100), 
      id_endereco      int,
      foreign key      (id_endereco)  REFERENCES  tb_endereco (id_endereco) on delete cascade
      ); 
    
   
   
    CREATE TABLE            tb_venda (
      id_venda              int primary key auto_increment, 
      id_cliente            int, 
      ds_nota_fiscal        varchar(100), 
      tp_forma_pagamento    varchar(100), 
      qtd_parcelas          int, 
      dt_venda              DateTime, 
      id_endereco_entrega   int,
       foreign key         (id_cliente)            REFERENCES  tb_cliente  (id_cliente)   on delete cascade,
       foreign key         (id_endereco_entrega)   REFERENCES  tb_endereco (id_endereco)  on delete cascade
      ); 
      
   
   
    CREATE TABLE           tb_venda_item (
      id_vendas_item       int primary key auto_increment, 
      id_venda             int, 
      id_produto           int,
      foreign key         (id_venda)    REFERENCES   tb_venda    (id_venda)   on delete cascade,
      foreign key         (id_produto)  REFERENCES   tb_produto  (id_produto) on delete cascade
      ); 
  ````````
  
  
## Insert Into


````sql
 INSERT INTO tb_categoria  (nm_categoria)
    VALUES                    ("Pesças de Computador"), 
                              ("Materia de Manutenção"),
                              ("Jogos"), 
                              ("Consoles"),
                              ("Filmes"),
                              ("Celulares");
                                            
                    
                      
                      
                    
   INSERT INTO tb_produto    (id_categoria, nm_produto, vl_preco)
   VALUES                    (1, "Memoria RAM - Adata", 200.90), 
                             (1, "Memoria RAM - Advance", 300.50), 
                             (1, "Memoria RAM - Blitz", 255.90),
                             (3, "Horizon Zero Dawn", 300.90), 
                             (4, "PS4 -PlayStation 4", 2554.60), 
                             (4, "XBOX ONE", 2454.30),
                             (1, "Placa Mãe - Gigabyte B450", 999.60), 
                             (1, "Cooler - RR-H412-20PK-R2", 152.90),
                             (1, "Cooler Black Cover - RR-212TK-16PR-R1", 259.90),
                             (1, "Cooler - MFL-B2DN-183PA-R1", 309.90), 
                             (2, "Chave de fenda - Philips", 4.58), 
                             (2, "Conjunto de Chaves - Philips", 48.99), 
                             (5, "O Hobbit: Uma Jornada Inesperada", 19.60), 
                             (5, "O Hobbit Combo dos 3 filmes", 69.90), 
                             (6, "samsung s10", 1869.00), 
                             (6, "samsung s9 plus", 2999.00), 
                             (3, "watch dogs 2", 67.99), 
                             (3, "watch dogs ", 57.99), 
                             (3, "resident evil 8", 269.99), 
                             (3, "Dragon ball z kakarot", 174.90);
                          
                          
                          
                          
                          
                          
                          
    INSERT INTO tb_estoque   (id_produto, qtd_minima, qtd_disponivel)  
    VALUES                   (1, 200, 100),
                             (2, 200, 200),
                             (3, 200, 50),
                             (4, 100, 50),
                             (5, 600, 500),
                             (6, 600, 500),
                             (7, 200, 150),
                             (8, 200, 150),
                             (9, 200, 100),
                             (10, 200, 150),
                             (11, 200, 150),
                             (12, 250, 200),
                             (13, 100, 53),
                             (14, 100, 58),
                             (15, 700, 200),
                             (16, 650, 250),
                             (18, 750, 530),
                             (17, 730, 580),
                             (19, 770, 670),
                             (20, 760, 600);
                             
                             
                             
    INSERT INTO tb_endereco  (ds_cep, ds_endereco, nr_endereco, ds_cidade)
    VALUES                  ("06620-395","Endereço Alameda Santa Monica","35","Jandira"), 
                             ("06707-335","Rua dos Peixinhos", "08","Cotia"),
                             ("13145-539","Rua Silmara Aparecida dos Santos","05","Paulínia"),
                             ("06190-160","Avenida Hildebrando de Lima","38","Osasco"),
                             ("12224-834","Rua Otacílio Alves Caldeira","25","São José dos Campos"),
                             ("16080-740","Rua Maria Agulhiari","07","Araçatuba"),
                             ("19913-420","Rua Doutor Paulo Ribeiro de Moraes","17","Ourinhos"),
                             ("13223-334","Rua D","45","Várzea Paulista"),
                             ("09782-510","Rua Manoel Vitaldo Carmo","58","São Bernardo do Campo"),
                             ("13174-490","Rua Luiz Fava","36","Sumaré"),
                             ("04952-030","Rua Jean Bart","78","São Paulo"),
                             ("07053-171","Rodovia Fernão Dias","18","Guarulhos"), 
                             ("06700-625","Rua Acre","21","Cotia"),
                             ("11677-760","Rua Cidade de Miracatú","32","Caraguatatuba"),
                             ("13067-180","Rua João Cirino"," 86","Campinas"),
                             ("18275-020","Rua Nho Nho da Botica","62","Tatuí"),
                             ("06327-040","Rua Itanhaém","49","Carapicuíba"),
                             ("16201-192","Rua Roberto Babolim","25","Birigüi"),
                             ("12327-663","Rua São Tomé","54","Jacareí"),
                             ("09784-475","Rua Padre Ângelo Ceronni","68","São Bernardo do Campo"),
                             ("12324-340","Rua Graciliano Ramos","06","Jacareí"),
                             ("08692-040","Rua Ulisses Isaias de Almeida","57","Suzano"),
                             ("05551-110","Rua São Jorge","64","São Paulo"),
                             ("08613-900","Rua Prudente de Moraes 4006","94","Suzano"),
                             ("13256-220","Rua Santo Bredariol","11","Itatiba");
        
        
     INSERT INTO tb_cliente  (nm_cliente, ds_cpf, id_endereco)
     Values                  ("Breno Cardoso Azevedo","563.271.450-00", 1),
                             ("Tiago Goncalves Almeida","655.843.780-54", 2),
                             ("Kauã Gomes Rodrigues","714.154.260-40", 3),
                             ("Fábio Lima Martins","532.399.470-30", 4),
                             ("Samuel Cavalcanti Cardoso","094.098.210-29", 5),
                             ("Pedro Almeida Barbosa","226.323.710-07", 6),
                             ("Arthur Ferreira Araujo","831.570.950-05", 7),
                             ("Luís Cavalcanti Barros","132.904.770-29", 8),
                             ("Pedro Rocha Cunha","597.791.220-01", 9),
                             ("Nicolash Martins Cunha","542.422.410-54", 10),
                             ("Vitor Goncalves Pereira","335.011.490-34", 11),
                             ("Gustavo Rocha Sousa","711.125.760-02", 12),
                             ("Leonardo Pinto Ferreira","837.951.050-05", 13),
                             ("Igor Araujo Carvalho","577.767.070-90", 14),
                             ("Renan Ribeiro Martins","962.963.920-36", 15),
                             ("Arthur Fernandes Barbosa","120.777.850-80", 16),
                             ("Caio Cardoso Correia","268.722.550-99", 17),
                             ("Júlio Dias Martins","324.757.430-18", 18),
                             ("Diego Sousa Pinto","208.568.730-04", 19),
                             ("Lucas Almeida Ferreira", "536.407.710-10", 20),
                             ("Rodrigo Ferreira Barbosa", "274.299.350-95", 21),
                             ("Miguel Araujo Sousa", "829.288.290-16", 22),
                             ("Bruno Castro Santos","278.562.180-88", 23),
                             ("Kauan Fernandes Santos","998.111.190-23", 24),
                             ("Tomás Martins Correia","669.387.090-25", 25);
                             
                             
                             
       INSERT INTO  tb_venda (id_cliente, ds_nota_fiscal, tp_forma_pagamento, qtd_parcelas, dt_venda, id_endereco_entrega)
       values                (1,  "5440", "Credito",  12, '2021-02-12', 1),                         
                             (2,  "1384", "Credito",   7, '2020-07-15', 2),
                             (3,  "5741", "Debitto",   0, "2019-08-20", 3),
                             (4,  "0465", "Cerdito",   8, "2018-05-15", 4),
                             (5,  "6949", "Credito",   5, "2018-06-18", 5),
                             (6,  "0133", "Credito",  25, "2017-05-21", 6),
                             (7,  "2229", "Credito",  12, "2018-09-23", 7),
                             (8,  "0418", "Credito",  10, "2016-12-02", 8),
                             (9,  "1266", "Credito",  11, "2018-11-03", 9),
                             (10, "2200", "Credito",  8, "2019-02-15", 10),
                             (11, "6851", "Credito",  6, "2018-03-14", 11),
                             (12, "0522", "Credito",  6, "2017-05-06", 12),
                             (13, "0523", "Credito", 12, "2019-02-20", 13),
                             (14, "0524", "Credito", 10, "2019-12-01", 14),
                             (15, "0525", "Credito", 15, "2018-09-25", 15),
                             (16, "0526", "Credito", 14, "2019-09-22", 16),
                             (17, "0527", "Credito", 10, "2018-08-26", 17),
                             (18, "0528", "Credito",  3, "2019-01-25", 18),
                             (19, "0529", "Credito", 13, "2018-05-20", 19),
                             (20, "0510", "Credito", 10, "2018-12-17", 20),
                             (21, "0511", "Credito", 10, "2019-05-17", 21),
                             (22, "0512", "Credito", 10, "2020-11-16", 22),
                             (23, "0513", "Credito", 10, "2021-05-28", 23),
                             (24, "0514", "Credito", 10, "2018-07-19", 24),             
                             (25, "0515", "Credito", 10, "2019-05-16", 25);
                         
                         
                         
        INSERT INTO tb_venda_item (id_venda, id_produto)
        Values                    (1, 1),
                                  (1, 2),
                                  (1, 3),
                                  (1, 5),
                                  (1, 20),
                                  (2, 1),
                                  (2, 2),
                                  (2, 3),
                                  (2, 19),
                                  (3, 19),
                                  (3, 20),
                                  (4, 20),
                                  (4, 8),
                                  (5, 2),
                                  (5, 3),
                                  (5, 9),
                                  (6, 20),
                                  (6, 19),
                                  (7, 2),
                                  (7, 12),
                                  (8, 11),
                                  (9, 10),
                                  (10, 2),
                                  (10, 5),
                                  (11, 17),
                                  (11, 18),
                                  (12, 15),
                                  (12, 16),
                                  (13, 20),
                                  (14, 14),
                                  (14, 13),
                                  (15, 10),
                                  (15, 2),
                                  (16, 3),
                                  (17, 4),
                                  (18, 5),
                                  (19, 6),
                                  (20, 7),
                                  (21, 8),
                                  (22, 9),
                                  (23, 10),
                                  (23, 20),
                                  (23, 18),
                                  (24, 19),
                                  (24, 12),
                                  (25, 20),
                                  (25, 18),
                                  (25, 4),
                                  (25, 5);
``````


