---
# System prepended metadata

title: SESSION DE BANCO DE DADOS

---

# SESSION DE BANCO DE DADOS

```sql=
CREATE TABLE tb_categoria (

id_categoria int PRIMARY KEY AUTO_INCREMENT,

nm_categoria varchar(255)

);

CREATE TABLE tb_produto (

id_produto int PRIMARY KEY AUTO_INCREMENT,

id_categoria int,

nm_produto varchar(255),

vl_preco decimal(12,2),

FOREIGN KEY (id_categoria) REFERENCES tb_categoria(id_categoria)

);

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)

);

CREATE TABLE tb_endereco (

id_endereco int PRIMARY KEY AUTO_INCREMENT,

ds_cep varchar(255),

ds_endereco varchar(255),

nr_endereco varchar(255),

ds_cidade varchar(255)

);

CREATE TABLE tb_cliente (

id_cliente int PRIMARY KEY AUTO_INCREMENT,

nm_cliente varchar(255),

ds_cpf varchar(255),

id_endereco int,

FOREIGN KEY (id_endereco) REFERENCES tb_endereco(id_endereco)

);

CREATE TABLE tb_venda (

id_venda int PRIMARY KEY AUTO_INCREMENT,

id_cliente int,

ds_nota_fiscal varchar(255),

tp_forma_de_pagamento varchar(255),

qtd_parcelas int,

dt_venda datetime,

id_endereco_venda int,

FOREIGN KEY (id_cliente) REFERENCES tb_cliente(id_cliente),

FOREIGN KEY (id_endereco_venda) REFERENCES tb_endereco(id_endereco)

);

CREATE TABLE tb_venda_item (

id_venda_item int PRIMARY KEY AUTO_INCREMENT,

id_venda int,

id_produto int,

FOREIGN KEY (id_produto) REFERENCES tb_produto(id_produto),

FOREIGN KEY (id_venda) REFERENCES tb_venda(id_venda)

);

INSERT INTO tb_categoria (nm_categoria)
VALUES 
("Elétrodomestico"),
("Livro"),
("Brinquedo"),
("Decoração"),
("Alimento"),
("Acessório");

INSERT INTO  tb_produto ( id_categoria, nm_produto, vl_preco)

VALUES 
(2, "Inferno", 49.99),
(1, "Redmi Note 7", 1299.90),
(5, "Bolacha Trakinas de limão", 2.99),
(3, "Jogo de cartas Duno", 9.99),
(2, "Chainsaw Man, vol.1", 30.90),
(4, "Luminária Cogumelo Mário", 50.00),
(1, "Geladeira Samsung Interativa i9", 5999.99),
(2, "Do Check-out à Session, por Brunex", 19.99),
(1, "i9 da Positivo", 9.99),
(5, "Podrão de Sto. Amaro", 15.99),
(1, "Gato de tv a cabo", 20),
(4, "Tapete", 50),
(5, "Leite unidade", 4),
(6, "Guarda-chuva Katana", 25),
(6, "Colar olho de gato", 10),
(6, "Mochila Leon BrawlStars", 20),
(1, "Liquidificador", 100),
(6, "Anel de coco", 2),
(4, "Travesseiro One Piece-Doflamingo", 27.90),
(3, "Dados perolados RPG", 14.90);

INSERT INTO tb_estoque (id_produto, qtd_minima, qtd_disponivel)

VALUES
(1, 1, 200),
(2, 1, 130),
(3, 1, 233),
(4, 1, 120),
(5, 1, 800), 
(6, 1, 544), 
(7, 1, 777), 
(8, 1, 986),
(9, 1, 621),
(10, 1, 911),
(11, 1, 979),
(12, 1, 2),
(13, 1, 1),
(14, 1, 5), 
(15, 1, 102),
(16, 1, 875),
(17, 1, 421),
(18, 1, 543),
(19, 1, 156),
(20, 1, 666);

INSERT INTO  tb_endereco ( ds_cep, ds_endereco, nr_endereco, ds_cidade)

VALUES 
( "0403210","Rua dos passes", "03", "São Paulo"),
( "0403210", "Rua dos passes", "28", "São Paulo"),
( "0397020", "Rua Gato", "12", "São Paulo"),
( "0397020", "Rua Gato", "12", "São Paulo"),
( "0902560", "Rua Diguin Heitor", "01", "Carpazinha"),
( "0902560", "Rua Diguin Heitor", "09", "Carpazinha"),
( "8903838", "Rua Reinado Alan", "30", "Acre"),
( "8903838", "Rua Reinado Alan", "70", "Acre"),
( "04809100", "Rua Henriqueta Salvadore Giacometti", "32", "São Paulo"),
( "04809100", "Rua Henriqueta Salvadore Giacometti", "27", "São Paulo"),
( "0213578", "Rua Vai-Vai", "40", "São Paulo"),
( "0213578", "Rua Vai-Vai", "12", "São Paulo"),
( "9803231", "Rua Calçada das Areias", "23", "Guarulhos"),
( "9803231", "Rua Calçada das Areias", "89", "Guarulhos"),
( "0567843", "Rua Violão Azulado", "03", "Natal"),
( "0567843", "Rua Violão Azulado", "54", "Natal"),
( "0233366", "Rua Ventos Ardilosos", "61", "Duque de Caxias"),
( "0233366", "Rua Ventos Ardilosos", "233", "Duque de Caxias"),
( "7112191", "Alcatra Braga", "73", "Jaboatão dos Guararapes"),
( "7112191", "Alcatra Braga", "91", "Jaboatão dos Guararapes");


INSERT INTO tb_cliente (nm_cliente, ds_cpf, id_endereco)

VALUES 
("Alan dos Reis", "283.184.284-18", 8),
("Edgar Heitor", "193.282.343-02", 5),
("Homer Simpson", "832.134.182-90", 2),
("Alisson da Silva", "192.434.533-91", 20),
("Roberto Jaime", "922.324.563-94", 19),
("Brunex de Oliva", "694.023.980-40", 10),
("Ana Carolina", "671.858.230-13", 1),
("Gabriel Looze", "693.580.480-93", 1),
("Chirley Lucimari", "986.925.680-58", 8),
("Kevin Ribamar", "123.537.080-13", 6),
("Alhan D.W.", "894.394.700-38", 9),
("Danielly Cristina", "087.085.990-09", 4),
("Bruno Covas", "512.334.690-29", 12),
("Raffaelo Lanbe", "299.308.750-93", 18), 
("Arthur Cervero", "945.637.220-06", 7),
("Joui Jouki", "640.348.170-38", 7),
("Cesar Oliveira Cohen", "274.601.800-41", 7),
("Ivete S.", "746.679.380-05", 7),
("Dante Carvalho", "652.349.130-74", 17),
("Lilian Garde", "661.574.920-31", 17),
("Clara Garde", "104.822.030-30", 17),
("Robert DeNiro", "478.108.650-05", 13),
("Vincento Vânio Gogh", "735.632.480-60", 14),
("Charlotte Lady", "336.869.880-03", 9),
("Cuca Veludo", "508.492.370-33", 3);

INSERT INTO tb_venda (id_cliente, ds_nota_fiscal, tp_forma_de_pagamento, qtd_parcelas, dt_venda, id_endereco_venda)

VALUES 
(1, "32270895053", "Cartão de crédito", 7, "2021-03-12", 8),
(1, "10613624009", "Boleto bancário", 0, "2021-12-31", 8),
(2, "29492842949", "Boleto bancário", 10, "2012-01-01", 5),
(2, "93939922848", "À vista", 0, "2013-07-23", 5),
(3, "17216326362", "Cartão de crédito", 70, "2020-01-26", 2),
(3, "47463473747", "Cartão de crédito", 100, "2021-01-26", 2),
(4, "08967776004", "Cartão de débito", 3, "2000-07-09", 20),
(4, "24096035050", "Boleto bancário", 12, "2023-04-19", 20),
(5, "84769917031", "Cheque especial", 0, "2020-05-14", 19),
(5, "26137803040", "Boleto bancário", 0, "2020-12-20", 19),
(6, "77380333046", "Boleto bancário", 2, "2021-05-17", 10),
(6, "92340161061", "Cartão de débito", 3, "2021-09-19", 10),
(7, "65143079063", "Cartão de crédito", 12, "2019-10-24", 1),
(7, "94712518006", "Cartão de crédito", 5, "2019-10-29", 1),
(8, "62255455064", "Boleto bancário", 0, "2021-08-16", 1),
(8, "50620086033", "Boleto bancário", 0, "2021-10-31", 1),
(9, "03260936050", "Cartão de crédito", 6, "2013-05-22", 8),
(9, "77374365020", "Boleto bancário", 2, "2025-01-01", 8),
(10, "99884576009", "Cartão de débito", 12, "2020-02-27", 6),
(10, "27863545013", "Cartão de crédito", 10, "2021-03-17", 6),
(11, "21579289010", "Boleto bancário", 5, "2022-01-18", 9),
(11, "42834297088", "Cartão de crédito", 10, "2021-12-31", 9),
(12, "49243397095", "Boleto bancário", 3, "2018-04-26", 4),
(12, "10092437052", "Boleto bancário", 2, "2019-02-22", 4),
(13, "61713083078", "Cartão de crédito", 20, "2022-05-17", 12),
(13, "83436309044", "Cartão de crédito", 11, "2021-12-14", 12),
(14, "28567314062", "Boleto bancário", 4, "2020-02-17", 18),
(14, "00234619007", "À vista", 0, "2012-12-12", 18),
(15, "91150540044", "Dinheiro", 0, "2021-12-21", 7),
(15, "57797850070", "Boleto bancário", 2, "2015-03-25", 7),
(16, "67449453002", "Boleto bancário", 4, "2021-03-11", 7),
(16, "03759433073", "Dinheiro", 2, "2013-04-07", 7),
(17, "68960490067", "Cartão de crédito", 14, "2022-04-19", 7),
(17, "04790379060", "Dinheiro", 3, "2024-02-21", 7),
(18, "18620963090", "Cartão de débito", 1, "2021-08-19", 7),
(18, "87789606069", "Dinheiro", 5, "2020-09-10", 7),
(19, "45374214012", "Cartão de débito", 2, "2030-02-22", 17),
(19, "78158616011", "Cartão de crédito", 9, "2027-03-27", 17),
(20, "35747422073", "Dinheiro", 20, "2021-09-26", 17),
(20, "05496091055", "Dinheiro", 12, "2022-10-31", 17),
(21, "94579040015", "Cartão de crédito", 5, "2021-11-19", 17),
(21, "53425804049", "Dinheiro", 10, "2001-09-11", 17),
(22, "27456522065", "Cartão de débito", 1, "2010-03-16", 13),
(22, "76589034001", "Cartão de débito", 7, "2020-03-16", 13),
(23, "31240810059", "Cheque especial", 2, "2017-03-18", 14),
(23, "71358350000", "Dinheiro", 2, "2004-11-19", 14),
(24, "96853230035", "Cartão de crédito", 19, "2043-12-09", 9),
(24, "65604201081", "Dinheiro", 3, "2024-10-17", 9),
(25, "84931507034", "Cartão de débito", 10, "2021-07-28", 3),
(25, "00898029007", "Cheque especial", 2, "2010-09-27", 3);

INSERT INTO tb_venda_item (id_venda, id_produto)

VALUES 
(1,1),
(2,2),
(3,3),
(4,4),
(5,5),
(6,6),
(7,7),
(8,8),
(9,9),
(10,10),
(11,11),
(12,12),
(13,13),
(14,14),
(15,15),
(16,16),
(17,17),
(18,18),
(19,19),
(20,20),
(21,1),
(22,2),
(23,3),
(24,4),
(25,5),
(26,6),
(27,7),
(28,8),
(29,9),
(30,10),
(31,11),
(32,12),
(33,13),
(34,14),
(35,15),
(36,16),
(37,17),
(38,18),
(39,19),
(40,20),
(41,1),
(42,2),
(43,3),
(44,4),
(45,5),
(46,6),
(47,7),
(48,8),
(49,9),
(50,10);

```