-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbDistribuidora.sql
129 lines (113 loc) · 3.51 KB
/
dbDistribuidora.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
drop database dbdistribuidora;
create database dbdistribuidora;
use dbdistribuidora;
create table tbestado(
estadoUF char(2) not null,
UFID int primary key auto_increment
);
create table tbcidade(
idcidade int primary key auto_increment,
cidade varchar(50),
UFID int,
foreign key (UFId) references tbestado(UFId)
);
create table tblog(
logradouro varchar(100) not null,
bairro varchar(50),
cep numeric(8) primary key,
idcidade int,
foreign key (idcidade) references tbcidade(idcidade)
);
create table tbendereco(
IDendereco int primary key auto_increment,
compEndereco varchar(50),
cep numeric(8),
foreign key (cep) references tblog(cep)
);
create table tbpessoa(
idCli int primary key auto_increment,
nomeCli varchar(200) not null,
telPessoa int not null,
numLog numeric(6) not null,
IDendereco int,
foreign key (IDendereco) references tbendereco(IDendereco)
);
create table tbclientePJ(
cnpj numeric(14) not null primary key,
IE numeric(11) not null,
idCli int,
foreign key (idCli) references tbpessoa(idCli)
);
CREATE TABLE tbclientePF (
cpf numeric(11) NOT NULL PRIMARY KEY,
dataNasc DATE not null,
rg numeric(9) not null,
rgdig char(1) not null,
sexoCli char(1),
idCli INT,
FOREIGN KEY (idCli)
REFERENCES tbpessoa (idCli)
);
----------
create table tbfornecedor(
codFornecedor numeric(10) auto_increment primary key,
cnpj numeric(14) not null unique,
nomeFornecedor varchar(200) not null,
tel int
);
create table tbproduto(
codigoBarras numeric(14) primary key unique,
nomeProd varchar(200) not null,
valorUnit decimal(7,2) not null,
qtd int
);
create table tbprodutoComprado (
CodigoBarras bigint not null,
NotaFiscal int primary key,
valoritem decimal(7,2) not null,
qtd int not null,
foreign key (CodigoBarras) references tbproduto(codigobarras)
);
create table tbcompra(
NotaFiscal int primary key not null,
dataCompra date not null,
valorTotal decimal(7,2) not null,
qtdTotal int not null,
codFornecedor int ,
codigoBarras bigint,
foreign key (NotaFiscal) references tbprodutocomprado(NotaFiscal),
foreign key (codFornecedor) references tbfornecedor(codFornecedor),
foreign key (codigoBarras) references tbproduto(codigoBarras)
);
create table tbestoque(
idestoque int auto_increment primary key,
qtd int,
valorItem decimal(7,2),
codigoBarras bigint,
foreign key (codigoBarras) references tbproduto(codigoBarras)
);
----------------------------
create table tbNF(
NF int primary key,
totalNota decimal(7,2) not null,
dataEmissao date not null,
codigoBarras bigint,
foreign key (codigoBarras) references tbproduto(codigoBarras)
);
create table tbvenda(
numeroVenda int primary key,
dataVenda datetime,
totalVenda decimal(7,2) not null,
NF int,
idCli int not null,
foreign key (NF) references tbNF(NF),
foreign key (idCli) references tbpessoa(idCli)
);
create table tbItemVenda(
numeroVenda int primary key,
CodigoBarras numeric(14),
ValorItem decimal(7,2) not null,
qtd int not null,
foreign key (numeroVenda) references tbvenda(numeroVenda),
foreign key (CodigoBarras) references tbproduto(codigoBarras)
)