TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Exercícios Linguagem de Programação de Banco de Dados, UNIP 2020 Ciências da Computação

Por:   •  2/11/2020  •  Trabalho acadêmico  •  3.224 Palavras (13 Páginas)  •  355 Visualizações

Página 1 de 13

/* ISSO AQUI É PARA CRIAR AS TABELAS

CREATE DATABASE vendasPF;

USE vendasPF;

CREATE TABLE categorias (

IDCategoria smallint NOT NULL,

NomeCategoria varchar(25) NOT NULL,

PRIMARY KEY (IDCategoria)

);

CREATE TABLE clientes (

IDCliente char(5) NOT NULL,

NomeCliente varchar(40) NOT NULL,

DataNasc date,

Endereco varchar(60),

Cidade varchar(15),

UF char(2),

CEP varchar(10),

Telefone varchar(13),

IDTerritorio int,

PRIMARY KEY (IDCliente)

);

CREATE TABLE fornecedores (

IDFornecedor smallint NOT NULL,

NomeFornecedor varchar(40) NOT NULL,

NomeContato varchar(30),

PRIMARY KEY (IDFornecedor)

);

CREATE TABLE funcionarios (

IDFuncionario smallint NOT NULL,

Nome varchar(40) NOT NULL,

NivelEscolar char(1),

DataNasc date,

DataAdmissao date,

Endereco varchar(60),

Cidade varchar(15),

UF char(2),

Cep varchar(10),

TelResidencial varchar(13),

Reportase smallint,

PRIMARY KEY (IDFuncionario)

);

CREATE TABLE funcionarios_territorios (

IDFuncionario smallint NOT NULL,

IDTerritorio int NOT NULL,

PRIMARY KEY (IDFuncionario,IDTerritorio)

);

CREATE TABLE pedidos (

IDPedido int NOT NULL,

IDCliente char(5),

IDFuncionario smallint,

IDFormaPgto tinyint,

DataPedido date,

DataRequisicao date,

DataEntrega date,

IDTransportadora tinyint,

Frete decimal(7,2),

NomeDestinatario varchar(40),

EnderecoDestinatario varchar(60),

CidadeDestinatario varchar(15),

UFDestinatario varchar(15),

CepDestinatario varchar(10),

PRIMARY KEY (IDPedido)

);

CREATE TABLE pedidos_detalhes

(

IDPedido int NOT NULL,

IDProduto smallint NOT NULL,

IDFornecedor smallint not null,

PrecoUnitario decimal(7,2) not null,

Qtde tinyint NOT NULL,

Desconto float NOT NULL,

PRIMARY KEY (IDPedido,IDProduto)

);

CREATE TABLE formasdePgto (

IDFormaPgto tinyint NOT NULL,

DescricaoFormaPgto varchar(20) NOT NULL,

QtdeParcelas tinyint NOT NULL,

PRIMARY KEY (IDFormaPgto)

);

CREATE TABLE produtos (

IDProduto smallint NOT NULL,

NomeProduto varchar(100) NOT NULL,

IDCategoria smallint NOT NULL,

IDFornecedor smallint NOT NULL,

PrecoUnitario decimal(7,2) NOT NULL,

UnidadesEmEstoque smallint NOT NULL,

PRIMARY KEY (IDProduto)

);

CREATE TABLE regioes (

IDRegiao tinyint NOT NULL,

DescricaoRegiao char(50) NOT NULL,

PRIMARY KEY (IDRegiao)

);

CREATE TABLE UFederacao (

UF char(2) not null,

NomeUF varchar(30) not null,

IDRegiao tinyint not NULL,

PRIMARY KEY (UF)

);

CREATE TABLE territoriosUF (

IDTerritorio int NOT NULL,

UF char(2) NOT NULL,

DescricaoTerritorio char(50) NOT NULL,

PRIMARY KEY (IDTerritorio, UF)

);

CREATE TABLE transportadoras (

IDTransportadora tinyint NOT NULL,

NomeTransportadora varchar(50) NOT NULL,

PRIMARY KEY (IDTransportadora)

);

-- FKs para as tabelas

ALTER TABLE clientes

ADD FOREIGN KEY (IDTerritorio)

...

Baixar como (para membros premium)  txt (25.9 Kb)   pdf (69.5 Kb)   docx (23.6 Kb)  
Continuar por mais 12 páginas »
Disponível apenas no TrabalhosGratuitos.com