Vous êtes sur la page 1sur 5

drop table if exists TBL_CARRINHO;

drop table if exists TBL_CATEGORIA;


drop table if exists TBL_CIDADE;
drop table if exists TBL_CLIENTE;
drop table if exists TBL_ENTREGA;
drop table if exists TBL_FORNECEDOR;
drop table if exists TBL_IMAGEM;
drop table if exists TBL_ITENS_PEDIDO;
drop table if exists TBL_PEDIDO;
drop table if exists TBL_PRODUTO;
drop table if exists TBL_PROMOCAO;
drop table if exists TBL_USUARIO;
/*==============================================================*/
/* Table: TBL_CARRINHO */
/*==============================================================*/
create table TBL_CARRINHO
(
CAR_SESSAO int not null,
CAR_QUANTIDADE numeric(5,2),
CAR_VALOR decimal(10,2),
CAR_DATA date,
primary key (CAR_SESSAO)
);
/*==============================================================*/
/* Table: TBL_CATEGORIA */
/*==============================================================*/
create table TBL_CATEGORIA
(
CAT_CODIGO int not null,
CAT_DESCRICAO varchar(30),
primary key (CAT_CODIGO)
);
/*==============================================================*/
/* Table: TBL_CIDADE */
/*==============================================================*/
create table TBL_CIDADE
(
CID_CODIGO int not null,
CID_DECRICAO varchar(40) not null,
CID_UF char(2),
primary key (CID_CODIGO)
);
/*==============================================================*/
/* Table: TBL_CLIENTE */
/*==============================================================*/
create table TBL_CLIENTE
(
CLI_CODIGO int not null,
CID_CODIGO int not null,
CLI_NOME varchar(50) not null,
CLI__ENDERECO varchar(40),
CLI__NUMERO longtext,
CLI__COMPLEMENTO varchar(20),
CLI__BAIRRO varchar(30),
CLI__CEP char(10),
CLI__FONERES varchar(16),
CLI__FONECEL varchar(16),
CLI__FONECOM varchar(43),
CLI__CPF varchar(14),
CLI__RG varchar(20),
CLI__DATACADASTRO date,
CLI__DATANASC date,
CLI__EMAIL varchar(50),
CLI__LOGIN varchar(10),
CLI__SENHA varchar(10),
CLI__ULTCOMP date,
CLI__VALOR_ULTCOMP numeric(10,2),
CLI__VALOR_TOTAL numeric(10,2),
primary key (CLI_CODIGO)
);
/*==============================================================*/
/* Table: TBL_ENTREGA */
/*==============================================================*/
create table TBL_ENTREGA
(
ENT_CODIGO int not null,
CID_CODIGO int not null,
ENT_EDERECO varchar(60),
ENT_BAIRRO varchar(30),
ENT_CEP char(10),
primary key (ENT_CODIGO)
);
/*==============================================================*/
/* Table: TBL_FORNECEDOR */
/*==============================================================*/
create table TBL_FORNECEDOR
(
FOR_CODIGO int not null,
CID_CODIGO int not null,
FOR_RAZAOSOCIAL varchar(40) not null,
FOR_NOME_FANTASIA varchar(40),
FOR_ENDERECO varchar(40),
FOR_BAIRRO varchar(30),
FOR_FONE varchar(10),
FOR_RESPONSAVEL varchar(40),
FOR_EMAIL varchar(60),
FOR_CNPJ varchar(18),
FOR_CEP varchar(10),
primary key (FOR_CODIGO)
);
/*==============================================================*/
/* Table: TBL_IMAGEM */
/*==============================================================*/
create table TBL_IMAGEM
(
IMG_CODIGO int not null,
PROD_CODIGO int not null,
IMG_DESCRICAO text not null,
primary key (IMG_CODIGO)
);
/*==============================================================*/
/* Table: TBL_ITENS_PEDIDO */
/*==============================================================*/
create table TBL_ITENS_PEDIDO
(
PROD_CODIGO int not null,
PED_CODIGO int not null,
ITENS_QUANTIDADE numeric(5,2),
INTENS_VALOR dec(10,2),
primary key (PROD_CODIGO, PED_CODIGO)
);
/*==============================================================*/
/* Table: TBL_PEDIDO */
/*==============================================================*/
create table TBL_PEDIDO
(
PED_CODIGO int not null,
CLI_CODIGO int not null,
PED_DATA date not null,
PED_HORA time,
PED_VALORTOTAL decimal(10,2),
PED_VALORFRETE decimal(10,2),
PED_STATUS char(1),
PED_FORMATO char(1),
PED_OBSERVACAO text,
primary key (PED_CODIGO)
);
/*==============================================================*/
/* Table: TBL_PRODUTO */
/*==============================================================*/
create table TBL_PRODUTO
(
PROD_CODIGO int not null,
CAT_CODIGO int not null,
FOR_CODIGO int not null,
CAR_SESSAO int,
PROD_DESCRICAO varchar(40),
PROD_VALOR numeric(10,2),
PROD_QUANTIDADE numeric(10,1),
PROD_TIPO varchar(5),
PROD_OBS text,
PROD_IMAGEM varchar(60),
primary key (PROD_CODIGO)
);
/*==============================================================*/
/* Table: TBL_PROMOCAO */
/*==============================================================*/
create table TBL_PROMOCAO
(
PROM_CODIGO int not null,
PROM_DATAINI date,
PROM_DATAFIM date,
primary key (PROM_CODIGO)
);
/*==============================================================*/
/* Table: TBL_USUARIO */
/*==============================================================*/
create table TBL_USUARIO
(
USU_CODIGO int not null,
USU_NOME varchar(40) not null,
USU_LOGIN varchar(10) not null,
USU_SENHA varchar(10) not null,
USU_NIVEL char(1) not null,
primary key (USU_CODIGO)
);
alter table TBL_CLIENTE add constraint FK_CIDADE_CLIENTE foreign key (CID_CODIGO
)
references TBL_CIDADE (CID_CODIGO) on delete restrict on update restrict;
alter table TBL_ENTREGA add constraint FK_ENTREGA_CIDADE foreign key (CID_CODIGO
)
references TBL_CIDADE (CID_CODIGO) on delete restrict on update restrict;
alter table TBL_FORNECEDOR add constraint FK_FORNECEDOR_CIDADE foreign key (CID_
CODIGO)
references TBL_CIDADE (CID_CODIGO) on delete restrict on update restrict;
alter table TBL_IMAGEM add constraint FK_IMAGEM_PRODUTOS foreign key (PROD_CODIG
O)
references TBL_PRODUTO (PROD_CODIGO) on delete restrict on update restrict
;
alter table TBL_ITENS_PEDIDO add constraint FK_TBL_ITENS_PEDIDO foreign key (PRO
D_CODIGO)
references TBL_PRODUTO (PROD_CODIGO) on delete restrict on update restrict
;
alter table TBL_ITENS_PEDIDO add constraint FK_TBL_ITENS_PEDIDO2 foreign key (PE
D_CODIGO)
references TBL_PEDIDO (PED_CODIGO) on delete restrict on update restrict;
alter table TBL_PEDIDO add constraint FK_PEDIDO_CLIENTE foreign key (CLI_CODIGO)
references TBL_CLIENTE (CLI_CODIGO) on delete restrict on update restrict;
alter table TBL_PRODUTO add constraint FK_CARRINHO foreign key (CAR_SESSAO)
references TBL_CARRINHO (CAR_SESSAO) on delete restrict on update restrict
;
alter table TBL_PRODUTO add constraint FK_PRODUTOS_CATEGORIA foreign key (CAT_CO
DIGO)
references TBL_CATEGORIA (CAT_CODIGO) on delete restrict on update restric
t;
alter table TBL_PRODUTO add constraint FK_PRODUTO_FORNECEDOR foreign key (FOR_CO
DIGO)
references TBL_FORNECEDOR (FOR_CODIGO) on delete restrict on update restri
ct;

Vous aimerez peut-être aussi