· 7 years ago · Oct 26, 2018, 01:02 PM
1DROP DATABASE IF EXISTS loja;
2
3/*1)Crie o Banco de Dados LOJA, as tabelas e inclua os registros abaixo:*/
4
5CREATE DATABASE IF NOT EXISTS loja;
6USE loja;
7
8CREATE TABLE IF NOT EXISTS clientes(
9id integer auto_increment not null primary key,
10nome varchar(50) not null,
11endereco varchar(80),
12id_cidade integer);
13
14CREATE TABLE IF NOT EXISTS cidades(
15id integer auto_increment not null primary key,
16nome varchar(60) not null,
17uf varchar(2));
18
19CREATE TABLE IF NOT EXISTS produtos(
20id integer auto_increment not null primary key,
21descricao varchar(100) not null,
22codigo_barra integer,
23id_categoria integer,
24id_fornecedor integer);
25
26CREATE TABLE IF NOT EXISTS categorias(
27id integer auto_increment not null primary key,
28descricao varchar(60) not null);
29
30
31CREATE TABLE IF NOT EXISTS fornecedores(
32id integer auto_increment not null primary key,
33razao_social varchar(80) not null,
34id_cidade integer);
35
36
37
38
39
40select cid.nome, cli.id_cidade from clientes cli
41inner join cidades cid on cli.id_cidade = cid.id
42group by cli.id_cidade;
43
44select cat.nome, prod.id_categoria from produtos prod
45inner join categorias cat on prod.id_categoria = cat.id
46group by prod.id_categoria;
47
48select prod.nome,
49
50select cid.nome count (*) from fornecedores forn
51inner join cidades cid on forn.id_cidade = cid.id
52group by forn.id_cidade;