· 7 years ago · Sep 05, 2018, 03:36 AM
1-- mysql workbench forward engineering
2
3set @old_unique_checks=@@unique_checks, unique_checks=0;
4set @old_foreign_key_checks=@@foreign_key_checks, foreign_key_checks=0;
5set @old_sql_mode=@@sql_mode, sql_mode='traditional,allow_invalid_dates';
6
7
8-- -----------------------------------------------------
9-- table `estoque`.`usuario`
10-- -----------------------------------------------------
11create table if not exists `estoque`.`usuario` (
12 `cd_usuario` int not null,
13 `nm_usuario` varchar(200) not null,
14 `nm_senha` varchar(100) not null,
15 primary key (`cd_usuario`))
16engine = innodb;
17
18
19-- -----------------------------------------------------
20-- table `estoque`.`tipo_embalagem`
21-- -----------------------------------------------------
22create table if not exists `estoque`.`tipo_embalagem` (
23 `nm_tipo_embalagem` varchar(200) not null,
24 `id_tipo_embalagem` int not null,
25 primary key (`nm_tipo_embalagem`))
26engine = innodb;
27
28
29-- -----------------------------------------------------
30-- table `estoque`.`estoque`
31-- -----------------------------------------------------
32create table if not exists `estoque`.`estoque` (
33 `cd_produto` int not null,
34 `cd_ncm` int not null,
35 `ds_produto` varchar(200) not null,
36 `qt_produto` int not null,
37 `vl_unitario` decimal(10,2) not null,
38 `vl_total` decimal(10,2) not null,
39 `tipo_embalagem_nm_tipo_embalagem` varchar(200) not null,
40 primary key (`cd_produto`),
41 index `fk_estoque_tipo_embalagem_idx` (`tipo_embalagem_nm_tipo_embalagem` asc),
42 constraint `fk_estoque_tipo_embalagem`
43 foreign key (`tipo_embalagem_nm_tipo_embalagem`)
44 references `estoque`.`tipo_embalagem` (`nm_tipo_embalagem`)
45 on delete no action
46 on update no action)
47engine = innodb;
48
49
50-- -----------------------------------------------------
51-- table `estoque`.`lucro`
52-- -----------------------------------------------------
53create table if not exists `estoque`.`lucro` (
54 `cd_lucro` int not null,
55 primary key (`cd_lucro`))
56engine = innodb;
57
58
59-- -----------------------------------------------------
60-- table `estoque`.`notafiscal`
61-- -----------------------------------------------------
62create table if not exists `estoque`.`notafiscal` (
63 `cd_nfe` varchar(100) not null,
64 `dt_emissao` datetime not null,
65 `dt_criacao` datetime not null,
66 primary key (`cd_nfe`))
67engine = innodb;
68
69
70-- -----------------------------------------------------
71-- table `estoque`.`fornecedor`
72-- -----------------------------------------------------
73create table if not exists `estoque`.`fornecedor` (
74 `cd_fornecedor` int not null auto_increment,
75 `nm_razao` varchar(200) not null,
76 `nm_fantasia` varchar(200) not null,
77 `cd_cnpj` int not null,
78 `cd_ie` int not null,
79 `cd_cep` int null,
80 `ds_endereco` varchar(100) null,
81 `cd_numero` int(5) null,
82 `nm_bairro` varchar(45) null,
83 `nm_cidade` varchar(45) null,
84 `nm_estado` varchar(2) null,
85 `cd_tel1` int null,
86 `cd_tel2` int null,
87 `nm_vendedor` varchar(100) null,
88 `cd_telvendedor` int null,
89 `notafiscal_cd_nfe` varchar(100) not null,
90 primary key (`cd_fornecedor`),
91 index `fk_fornecedor_notafiscal1_idx` (`notafiscal_cd_nfe` asc),
92 constraint `fk_fornecedor_notafiscal1`
93 foreign key (`notafiscal_cd_nfe`)
94 references `estoque`.`notafiscal` (`cd_nfe`)
95 on delete no action
96 on update no action)
97engine = innodb;
98
99
100-- -----------------------------------------------------
101-- table `estoque`.`produto`
102-- -----------------------------------------------------
103create table if not exists `estoque`.`produto` (
104 `cd_produto` int not null,
105 `cd_ncm` int not null,
106 `ds_produto` varchar(200) not null,
107 `qt_produto` int not null,
108 `vl_unitario` decimal(10,2) not null,
109 `vl_total` decimal(10,2) not null,
110 primary key (`cd_produto`))
111engine = innodb;
112
113
114-- -----------------------------------------------------
115-- table `estoque`.`saida_produto`
116-- -----------------------------------------------------
117create table if not exists `estoque`.`saida_produto` (
118 `cd_produto_saida` int not null auto_increment,
119 `ds_produto` varchar(200) not null,
120 `qt_produto` int not null,
121 `vl_unitario` decimal(10,2) not null,
122 `dt_saida` datetime not null,
123 `produto_cd_produto` int not null,
124 primary key (`cd_produto_saida`),
125 index `fk_saida_produto_produto1_idx` (`produto_cd_produto` asc),
126 constraint `fk_saida_produto_produto1`
127 foreign key (`produto_cd_produto`)
128 references `estoque`.`produto` (`cd_produto`)
129 on delete no action
130 on update no action)
131engine = innodb;
132
133
134-- -----------------------------------------------------
135-- table `estoque`.`entrada_produto`
136-- -----------------------------------------------------
137create table if not exists `estoque`.`entrada_produto` (
138 `cd_produto_entrada` int not null auto_increment,
139 `cd_ncm` int not null,
140 `ds_produto` varchar(200) not null,
141 `qt_produto` int not null,
142 `vl_unitario` decimal(10,2) not null,
143 `dt_entrada` datetime null,
144 `produto_cd_produto` int not null,
145 primary key (`cd_produto_entrada`),
146 index `fk_entrada_produto_produto1_idx` (`produto_cd_produto` asc),
147 constraint `fk_entrada_produto_produto1`
148 foreign key (`produto_cd_produto`)
149 references `estoque`.`produto` (`cd_produto`)
150 on delete no action
151 on update no action)
152engine = innodb;
153
154
155set sql_mode=@old_sql_mode;
156set foreign_key_checks=@old_foreign_key_checks;
157set unique_checks=@old_unique_checks;