Advertisement
11eimilia11

acho q dessa vez ta certo

Jan 6th, 2018
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 52.16 KB | None | 0 0
  1. CREATE SCHEMA IchibaSuperMarket;
  2. USE IchibaSuperMarket;
  3.  
  4.  
  5. -- TABELA DE CURSOS xxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxx createdyes 13
  6.  
  7. CREATE TABLE curso (
  8.  
  9. id char(4),
  10. cargahoraria integer(4) not null CHECK ( cargahoraria > 0 ),
  11. descricao varchar(40),
  12. primary key(id)
  13. );
  14.  
  15. -- inserindo valores para curso OK
  16.  
  17. INSERT INTO curso VALUES
  18.  
  19. ( '7070', 12 , 'entregas'),
  20. ( '1010' , 20, 'libras'),
  21. ( '2276' , 5 , 'marketing'),
  22. ( '9085' , 13 , 'informatica'),
  23. ( '7324' , 7 , 'financas'),
  24. ( '8012' , 60 , 'ingles'),
  25. ( '3390', 30 , 'relacoes humanas'),
  26. ( '8344' , 30 , 'estatistica'),
  27. ( '5793' , 40 , 'circuitos'),
  28. ( '3333' , 20 , 'ginastica laboral'),
  29. ( '5449', 40 , 'mecanica'),
  30. ( '7573' , 20, 'administracao'),
  31. ( '9090' , 40 , 'programacao'),
  32. ( '2101' , 40 , 'espanhol');
  33.  
  34. -- TABELA DE FUNCIONARIOS INCOMPLETA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  35.  
  36. CREATE TABLE funcionario (
  37.  
  38. CPF char(11) ,
  39. id_jornada char(4) not null,
  40. seq_filial char(4),
  41. cnpj_matriz char(14) not null,
  42. data_admissao date,
  43. sex enum ('M', 'F'),
  44. estado_civil varchar(10),
  45. login varchar(60) default 'func' ,
  46. senha varchar(15) default 'func',
  47. RG char(7) not null UNIQUE,
  48. nome varchar(45),
  49. situacao varchar(10) ,
  50. endereco varchar(45),
  51. primary key(CPF),
  52. foreign key (id_jornada) references jornadatrabalho (id) ,
  53. foreign key ( seq_filial ) references filial (seq),
  54. foreign key (cnpj_matriz) references matriz (CNPJ)
  55.  
  56. );
  57.  
  58. -- inserindo valores para funcionario
  59.  
  60. INSERT INTO funcionario (CPF, id_jornada, seq_filial, cnpj_matriz, data_admissao, sex, estado_civil, login, senha, RG, nome, situacao, endereco) VALUES
  61.  
  62. ('77491222226' , '0001', '0001' , '23416393000114' , '2005-04-12' , 'F', 'solteiro' , 'helo.12' , '123' , '1259312' , 'Heloisa Macedo de Souza' , 'ativo' , 'Rua Eloy Monteiro Nunes'),
  63. ('98243208909' , '0002' , '0001' ,'23416393000114' , '2007-07-25' , 'M' , 'casado' , 'Garza2019' , 'E3221' , '3654296' , 'Elias ChateauBriand Gomes' , 'inativo' , 'Avenida Paraíba'),
  64. ('57325297050' , '0003' , '0003' , '23416393000140', '2003-09-02', 'F', 'viuva' , 'Riggs642' , 'YM' , '4563573' , 'Maria Helena Rosendo' , 'ativo', 'Rua Pedro Viana Neto'),
  65. ('16565525749' , '0004' , '0002' , '23416393000114' , '2000-01-07', 'F', 'solteiro' , 'Eugene759' , 'XX133' , '2144770', 'Afrodite Bezerra das Flores' , 'ativo', 'Rua Amelia'),
  66. ('57859332507', '0005' , '0002' , '23416393000114' , '2006-02-02' , 'M' , 'solteiro' , 'TM1' , '98UJ' , '1555582' , 'Mauricio de Souza Carvalho' , 'ativo' , ' Rua da Concordia'),
  67. ('96202875763' , '0006' , '0003' , '23416393000140' , '2001-09-11' , 'F' , 'solteiro' , 'Juli.Alves' , '8900' , '3494135' , 'Juliana Macedo Pinheiro' , 'inativo' , 'Rua Tucano'),
  68. ('02123011878' , '0007' , '0004' , '23416393000169' , '2000-08-10' , 'M' , 'solteiro' , 'ana.mari' , 'bb34' , '1783833' , 'Mariana Siqueira Jardim' , 'ativo' , 'Rua Lealberto Leal'),
  69. ('15141182894' , '0008' , '0001' , '23416393000114' , '2005-06-13' , 'F' , 'casado' , 'dudu.arda' , '1999' ,'2267700', 'Bernadete Maria da Silva' , 'ativo' , 'Rua Guajuvira'),
  70. ('33666472214' , '0009' , '0004' , '23416393000169' , '2011-03-01' , 'F' , 'solteiro', 'ana.belle' , 'AX6','4137799','Anabelle Cristina Leal de Figueiredo' , 'ativo', 'Rua Manuel de Medeiros'),
  71. ('32568071001', '0010' , '0001' , '23416393000114' , '2010-09-26' , 'F' , 'casado' , 'bee.a' , '134N' ,'4163131', 'Ana Beatriz Castanho Guedes' , 'ativo', 'Rua Jornalista Benedito Cunha'),
  72. ('45321186898' , '0011', '0004', '23416393000169' , '2007-09-20', 'M' , 'solteiro' , 'alan.marq' , '0j7e' , '1557345','Allan Jose Malta de Souza' , 'inativo', ' Rua Projetada'),
  73. ('86147207504' , '0012' , '0004' , '23416393000169' , '2001-10-27' , 'F' , 'casado' , 'lelezinha' , '223d' ,' 3217467', 'Leticia Santana Rodrigues' , 'ativo' , 'Rua Felipe Guerra'),
  74. ('85902755239' , '0013' , '0003' , '23416393000140' , '2005-11-14' , 'F' , 'solteiro' , 'mwd2', '1332','2437550', 'Gabriela Amado Batista', 'ativo', 'Rua da Palma'),
  75. ('14073416260' , '0014' , '0002' , '23416393000114', '2000-02-14', 'M' , 'casado', 'mumu321', '9901',' 1190089','Jadiane Matoso dos Santos', 'ativo', 'Rua Real da Torre'),
  76. ('32970753502', '0015' , '0002' , '23416393000114' , '2013-01-10', 'F' , 'solteiro' , 'JH10' , '1132' , ' 2422874', 'Viviane Mendonca do Nascimento', 'ativo', 'Rua da Harmonia'),
  77. ('88356795591' , '0016' , '0003' , '23416393000140' , '2012-06-10', 'M' , 'casado', '991jj', '1233','1316411', 'Ronaldo Fagundes da Silva' , 'ativo', 'Rua da Praia');
  78.  
  79. -- TABELA DE ESTOQUISTA HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  80.  
  81.  
  82. CREATE TABLE estoquista(
  83.  
  84. seq char(4),
  85. CPF char(11),
  86. primary key (seq),
  87. CONSTRAINT fk_estoq foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  88.  
  89. );
  90.  
  91. -- inserindo valores para estoquista
  92.  
  93. INSERT INTO estoquista (CPF) VALUES
  94.  
  95. ('77491222226'),
  96. ('98243208909'),
  97. ('57859332507'),
  98. ('16565525749');
  99.  
  100. -- TABELA DE DBA HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  101.  
  102. CREATE TABLE DBA (
  103.  
  104. seq char(4),
  105. CPF char(11),
  106. primary key(seq),
  107. CONSTRAINT fk_dba foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  108.  
  109. );
  110. -- inserindo valores para dba
  111.  
  112. INSERT INTO DBA (CPF) VALUES
  113.  
  114. ('45321186898');
  115.  
  116. -- TABELA DE GERENTE HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  117.  
  118. CREATE TABLE gerente(
  119.  
  120. seq char(4),
  121. CPF char(11),
  122. primary key(seq),
  123. CONSTRAINT fk_gerente foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  124.  
  125. );
  126.  
  127. -- inserindo valores para gerente
  128.  
  129. INSERT INTO gerente (CPF) VALUES
  130.  
  131. ('96202875763'),
  132. ('02123011878'),
  133. ('15141182894'),
  134. ('57325297050');
  135.  
  136. -- TABELA DE ENTREGADOR HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  137.  
  138. CREATE TABLE entregador(
  139.  
  140. seq char(4),
  141. CPF char(11),
  142. primary key(seq),
  143. CONSTRAINT fk_entregador foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  144.  
  145. );
  146.  
  147. -- inserindo valores na tabela entregador
  148.  
  149. INSERT INTO entregador (CPF) VALUES
  150. ('33666472214'),
  151. ('86147207504'),
  152. ('32970753502'),
  153. ('32568071001');
  154.  
  155. -- TABELA DE SUPERVISOR ESTOQUE HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  156.  
  157. CREATE TABLE supervisorestoque(
  158. seq char(4),
  159. CPF char(11),
  160. primary key(seq),
  161. CONSTRAINT fk_super foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  162.  
  163. );
  164.  
  165. -- inserindo valotes na tabela supervisorestoque
  166.  
  167. INSERT INTO supervisorestoque (CPF) VALUES
  168.  
  169. ('14073416260'),
  170. ('85902755239' ),
  171. ('88356795591');
  172.  
  173.  
  174. -- TABELA MULTVALORADA DE FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  175.  
  176. CREATE TABLE telefone_funcionario(
  177.  
  178. seq char(4),
  179. CPF char(11),
  180. telefone char(11),
  181. primary key(seq),
  182. CONSTRAINT fk_telefonefuncinario foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  183.  
  184. );
  185.  
  186. -- inserindo valores na tabela de telefone_funcionario
  187.  
  188. INSERT INTO telefone_funcionario ( seq , CPF, telefone ) VALUES
  189.  
  190. ('0001 ', '14073416260' , '08133552321'),
  191. ('0002 ', '85902755239' , '08132324567'),
  192. ('0003' ,'88356795591', '08131311111'),
  193. ('0004' ,'32568071001', '08134587831'),
  194. ('0005' ,'32970753502', '08132324502'),
  195. ('0006' ,'32970753502' , '08191912343'),
  196. ('0007' ,'33666472214' , '08199096532'),
  197. ('0008' ,'86147207504', '08132732100'),
  198. ('0009' ,'96202875763' , '08199690359');
  199.  
  200.  
  201. -- TABELA DE NOTIFICAÇÃO DADA A FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  202.  
  203. CREATE TABLE notificacao (
  204.  
  205. id char(4),
  206. cpf_fun char(11) not null,
  207. dia date not null,
  208. descricao varchar(80),
  209. primary key (id),
  210. foreign key (Cpf_fun) references funcionario (CPF)
  211.  
  212. );
  213.  
  214. -- inserindo valores na tabela de notificacao
  215.  
  216. INSERT INTO notificacao (id, cpf_fun, dia, descricao) VALUES
  217.  
  218. ('2940' , '33666472214' , '2014-02-30' , NULL), -- ENTREGADOR
  219. ('2941' , '86147207504' , '2015-03-06' , NULL), -- ENTREGADOR
  220. ('2942' , '32970753502' , '2015-06-02' , NULL), -- ENTREGADOR
  221. ('2943' , '33666472214' , '2014-07-20' , NULL),
  222. ('2944' , '33666472214' , '2014-07-20' , NULL),
  223. ('2945' , '16565525749' , '2014-02-30' , NULL),
  224. ('2946' , '33666472214' , '2015-03-06' , NULL),
  225. ('2947' , '33666472214' , '2015-06-02' , NULL),
  226. ('2948' , '77491222226' , '2014-07-20' , NULL),
  227. ('2949' , '88356795591' , '2014-07-20' , NULL),
  228. ('2950' , '45321186898' , '2014-07-20' , NULL),
  229. ('2951' , '86147207504' , '2014-02-30' , NULL);
  230.  
  231. -- TABELA DE NOTIFICAÇÃO DE MULTA DADA A FUNCIONARIO HERDA DE NOTIFICAÇÃO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx
  232. -- createdyes 13
  233. CREATE TABLE notif_multa (
  234.  
  235. seq char(4),
  236. id char(4),
  237. pontos_cnh int,
  238. valor float not null,
  239. cep char(8),
  240. complemento varchar(30),
  241. primary key(seq),
  242. CONSTRAINT fk_notmulta foreign key (id) references notificacao(id) ON DELETE CASCADE ON UPDATE CASCADE
  243.  
  244. );
  245.  
  246. -- inserindo dados para notif_multa
  247.  
  248. INSERT INTO notif_multa (seq, id , pontos, valor, cep, complemento) VALUES
  249.  
  250. ('0001' , '2940', 3 , 58.50 , 50789123 , 'Rua da Aurora'),
  251. ('0002' , '2940' ,4 , 198.50 , 54330315 , 'Rua Itacuruba'),
  252. ('0003' ,'2940' , 5 , 398.50 , 54315330 , 'Rua verdejantes');
  253.  
  254.  
  255.  
  256. -- TABELA DE NOTIFICAÇÃO ADVERTENCIA DADA A FUNCIONARIO HERDA DE NOTIFICAÇÃO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx
  257. -- createdyes 13
  258. CREATE TABLE notif_advertencia (
  259.  
  260. seq char(4),
  261. id char(4),
  262. descricao varchar(20),
  263. primary key(seq),
  264. CONSTRAINT fk_notadvert foreign key (id) references notificacao(id) ON DELETE CASCADE ON UPDATE CASCADE
  265. );
  266.  
  267. -- inserindo dados para notif_advertencia
  268.  
  269. INSERT INTO notif_advertencia (seq , id) VALUES
  270. ('0001' ,'2943'),
  271. ('0002' , '2944'),
  272. ('0003' ,'2945');
  273.  
  274. -- TABELA DE NOTIFICAÇÃO DE SUSPENSAO DADA A FUNCIONARIO HERDA DE NOTIFICAÇÃO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx
  275. -- createdyes 13
  276. CREATE TABLE notif_suspensao (
  277.  
  278. seq char(4),
  279. id char(4),
  280. data_inicio date not null,
  281. data_termino date not null,
  282. primary key(seq),
  283. CONSTRAINT not_suspen foreign key (id) references notificacao(id) ON DELETE CASCADE ON UPDATE CASCADE
  284. );
  285.  
  286. -- inseindo dados para notif_suspensao
  287.  
  288. INSERT INTO notif_suspensao ( seq , id , data_inicio , data_termino ) VALUES
  289.  
  290. ('0001 ', '2946 ' , '2015-06-02' , '2015-06-04' ),
  291. ('0002' ,'2947 ' , '2015-08-20' , '2015-08-23' ),
  292. ('0003' ,'2948 ' , '2015-09-10' , '2015-09-13' );
  293.  
  294.  
  295. -- TABELA DE NOTIFICAÇÃO DE FALTA DADA A FUNCIONARIO HERDA DE NOTIFICAÇÃO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx
  296. -- createdyes 13
  297. CREATE TABLE notif_falta (
  298.  
  299. seq char(4),
  300. id char(4),
  301. dia date,
  302. duracao int CHECK (duracao > 0 ),
  303. primary key(seq),
  304. CONSTRAINT fk_notfalta foreign key (id) references notificacao (id) ON DELETE CASCADE ON UPDATE CASCADE
  305. );
  306.  
  307. -- inserindo valores para notif_falta
  308.  
  309. INSERT INTO notif_falta (seq , id , dia ) VALUES
  310.  
  311. ('0001' ,' 2949 ' , '2015-06-01' ),
  312. ('0002',' 2950 ' , '2015-08-19' ),
  313. ('0003' ,' 2951 ' , '2015-09-09' );
  314.  
  315. -- TABELA DE FERIAS DE FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  316.  
  317. CREATE TABLE ferias (
  318.  
  319. id char(4),
  320. cpf_fun char(11) not null,
  321. numero_dias int not null,
  322. seq char(4) not null,
  323. data_inicio date not null,
  324. data_fim date not null,
  325. primary key (id),
  326. foreign key (cpf_fun) references funcionario (CPF)
  327.  
  328. );
  329.  
  330. -- insenrindo valores na tabela ferias
  331.  
  332. INSERT INTO ferias (id , cpf_fun , numero_dias , seq , data_inicio , data_fim) VALUES
  333.  
  334. ( ' 2340 ' , ' 96202875763 ' , 20 , '0001 ' , ' 2016-06-02' , '2016-06-22' ),
  335. ( ' 2341 ' , ' 32970753502 ' , 20 , '0002 ' , ' 2016-06-02' , '2016-06-22' ),
  336. ( ' 2342 ' , ' 45321186898 ' , 20 , '0003 ' , ' 2016-01-02' , '2016-01-22' ),
  337. ( ' 2343 ' , ' 57859332507 ' , 20 , '0004 ' , ' 2016-01-02' , '2016-01-22' ),
  338. ( ' 2344 ' , ' 14073416260 ' , 20 , '0005 ' , ' 2016-04-02' , '2016-04-22' );
  339.  
  340.  
  341. -- TABELA DE CONTRA CHEQUE xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  342.  
  343. CREATE TABLE contracheque (
  344.  
  345. mes_referencia char(2) CHECK( mes_referencia > 0 AND mes_referencia < 13 ),
  346. CPF char(11) not null,
  347. data_pagamento date not null,
  348. valor_bruto float(5) not null,
  349. valor_liqd float(5) not null,
  350. valor_desconto float(5),
  351. primary key ( mes_referencia ),
  352. foreign key(CPF) references funcionario(CPF)
  353.  
  354. );
  355.  
  356. -- inserindo valores na tabela contracheque
  357.  
  358. INSERT INTO contracheque (mes_referencia , CPF, data_pagamento , valor_bruto, valor_liqd, valor_desconto) VALUES
  359.  
  360. ('02', '96202875763' , '2017-02-15', 3250.30, 3237.68 , 12.32),
  361. ('03' , '96202875763', '2017-03-15' , 3250.30, 3237.68, 12.32),
  362. ('05' , '45321186898' , '2017-05-15' , 8720.55,8708.8, 11.75),
  363. ('01' , '57325297050' , '2017-01-15' , 5956.00, 5942.00 , 14.00),
  364. ('03' , '85902755239' ,'2017-03-15', 4567.32 , 4553.32 , 14.00),
  365. ('08' , '85902755239' , '2017-08-15',4567.32 , 4553.32 , 14.00),
  366. ('01', '96202875763' , '2017-01-15', 3250.30, 3237.68 , 12.32),
  367. ('11' , '45321186898' , '2017-11-15' , 8720.55,8708.8, 11.75),
  368. ('07' , '45321186898' , '2017-07-15' , 8720.55,8708.8, 11.75),
  369. ('04' , '45321186898' , '2017-04-15' , 8720.55,8708.8, 11.75),
  370. ('01' , '02123011878' , '2017-04-15' ,4567.32 , 4553.32, 14.00),
  371. ('05' ,'86147207504', '2016-05-16' , 3250.30, 3237.68 , 12.32);
  372.  
  373. -- TABELA DE JORNADA DE TRABALHO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes
  374.  
  375. CREATE TABLE jornadatrabalho (
  376.  
  377. id char(4) ,
  378. descricao varchar(60),
  379. trabalha_sabado boolean not null default true,
  380. primary key(id)
  381.  
  382. );
  383.  
  384. -- inserindo valores na tabela jornadatrabalho OK
  385.  
  386. INSERT INTO jornadatrabalho ( id , descricao , trabalha_sabado) VALUES
  387.  
  388. ('0001' , 'segunda a domingo' , true),
  389. ('0002' , NULL , false),
  390. ('0003' , 'trabalha feriados' , true),
  391. ('0004' , ' ' , true ),
  392. ('0005' , ' ' , false),
  393. ('0006' , ' ', false),
  394. ('0007' , 'trabalha feriados' , true),
  395. ('0008' , ' ' , true),
  396. ('0009' , ' ' , true),
  397. ('0010' , ' ', true ),
  398. ('0011' , ' ', true),
  399. ('0012', ' ', true),
  400. ('0013' , ' ' , true),
  401. ('0014', ' ' , true),
  402. ('0015' , ' ', true ),
  403. ('0016' , ' ' , false);
  404.  
  405.  
  406.  
  407.  
  408. -- TABELA DE TURNO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes
  409.  
  410. CREATE TABLE turno (
  411.  
  412. cod char(4),
  413. descricao varchar(60),
  414. hora_inicio time not null,
  415. hora_fim time not null,
  416. primary key (cod)
  417.  
  418. );
  419.  
  420. -- inserindo valores na tabela de turno OK
  421.  
  422. INSERT INTO turno ( cod, descricao , hora_inicio, hora_fim ) VALUES
  423.  
  424. ('0001' , ' ' , '07:30:00' , '16:30:00'),
  425. ('0002' , ' ', '08:40:00' , '17:40:00'),
  426. ('0003' , ' ' , '07:00:00' , '14:00:00'),
  427. ('0004' , ' ' , '11:00:00' , '17:00:00'),
  428. ('0005' , ' ' , '14:00:00' , '18:30:00'),
  429. ('0006' , ' ' , '13:35:00' , '19:45:00'),
  430. ('0007' , ' ' , '07:30:00' , '12:30:00'),
  431. ('0008' , ' ' , '07:10:00' , '13:30:00'),
  432. ('0009' , ' ' , '18:00:00' , '23:55:00'),
  433. ('0010' , ' ' , '00:00:01' , '08:00:01');
  434.  
  435.  
  436. -- TABELA DE DIA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes
  437.  
  438. CREATE TABLE dia (
  439. sequencial char(4),
  440. descricao varchar(60),
  441. primary key (sequencial)
  442.  
  443. );
  444.  
  445. -- inserindo valores na tabela de dia OK
  446.  
  447. INSERT INTO dia ( sequencial , descricao ) VALUES
  448.  
  449. ('0001' , ' segunda-feira' ),
  450. ('0002' , ' terça-feira' ),
  451. ('0003' , ' quarta-feira' ),
  452. ('0004' , ' quinta-feira' ),
  453. ('0005' , ' sexta-feira' ),
  454. ('0006' , ' sabado' ),
  455. ('0007' , ' domingo' );
  456.  
  457.  
  458. -- TABELA DE ENTREGA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  459.  
  460. CREATE TABLE entrega (
  461.  
  462. seq char(4) ,
  463. CPF_entregador char(11) not null,
  464. data_entrega date,
  465. hora_estimada time,
  466. primary key (seq),
  467. foreign key(CPF_entregador) references entregador(CPF)
  468.  
  469. );
  470.  
  471. -- inserindo valores na tabela de entrega
  472.  
  473. INSERT INTO entrega ( seq , CPF_entregador , data_entrega , hora_estimada ) VALUES
  474.  
  475. ('0001' , '33666472214' , '2016-04-09 ' , '07:30:00'),
  476. ('0002' , '33666472214' , '2016-04-09 ' , '19:45:00'),
  477. ('0003' , '33666472214' , '2016-04-09 ' , '18:00:00'),
  478. ('0004' , '33666472214' , '2016-04-09 ' , '09:30:00'),
  479. ('0005' , '33666472214' , '2016-04-09 ' , '13:30:00'),
  480. ('0006' , '86147207504' , '2016-04-02 ' , '06:30:00'),
  481. ('0007' , '86147207504' , '2016-04-02 ' , '11:45:00'),
  482. ('0008' , '86147207504' , '2016-04-02 ' , '14:00:00'),
  483. ('0009' , '86147207504' , '2016-04-02 ' , '015:30:00'),
  484. ('0010' , '86147207504' , '2016-04-02 ' , '14:30:00');
  485.  
  486.  
  487. -- TABELA DE COMPRA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  488.  
  489. CREATE TABLE compra (
  490.  
  491. cod char(4),
  492. seq_entrega char(4) not null,
  493. valor_total float not null CHECK( valor_total > 0 ),
  494. dia date not null,
  495. valor_total_desconto float CHECK (valor_total_desconto >= 0 ),
  496. statos boolean default true,
  497. primary key (cod),
  498. foreign key (seq_entrega) references entrega ( seq )
  499. );
  500.  
  501. -- inserindo valores na tabela de compra
  502.  
  503. INSERT INTO compra ( cod , seq_entrega , valor_total , dia , valor_total_desconto , statos ) VALUES
  504.  
  505. ('0001' , '0001 ' , 693 , '2016-04-09 ' , 0 , true ),
  506. ('0002' , '0002 ' , 789 , '2016-04-09 ' , 23.4 , true ),
  507. ('0003' , '0003 ' , 403 , '2016-04-09 ' , 4.2 , true ),
  508. ('0004' , '0004 ' , 233 , '2016-04-09 ' , 0 , true ),
  509. ('0005' , '0005 ' , 70 , '2016-04-09 ' , 0 , true ),
  510. ('0006' , '0006 ' , 2020 , '2016-04-02 ' , 20.2 , true ),
  511. ('0007' , '0007 ' , 400 , '2016-04-02 ' , 0 , true ),
  512. ('0008' , '0008 ' , 121 , '2016-04-02 ' , 0 , true ),
  513. ('0009' , '0009 ' , 133 , '2016-04-02 ' , 3.2 , true ),
  514. ('0010' , '0010 ' , 154 , '2016-04-02 ' , 0 , true );
  515.  
  516. -- TABELA DE COMPRA COMUM xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  517.  
  518. CREATE TABLE compra_comum (
  519.  
  520. seq char(4),
  521. cod char(4),
  522. primary key(seq),
  523. CONSTRAINT fk_compracomum foreign key (cod) references compra (cod) ON DELETE CASCADE ON UPDATE CASCADE
  524. );
  525.  
  526.  
  527. -- inserindo valores na tabela de compra comum
  528.  
  529. INSERT INTO compra_comum (seq , cod ) VALUES
  530.  
  531. ( '0001','0001' ),
  532. ('0002' , '0003' ),
  533. ('0003' , '0005' ),
  534. ( '0004' ,'0006' ),
  535. ( '0005' ,'0008' );
  536.  
  537. -- TABELA DE COMPRA PROGRAMADA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  538.  
  539. CREATE TABLE compra_programada (
  540. seq char(4),
  541. cod char(4),
  542. data_1 date not null,
  543. data2 date not null,
  544. esta_ativa boolean default true,
  545. primary key (seq),
  546. CONSTRAINT fk_compraprogramada foreign key (cod) references compra (cod) ON DELETE CASCADE ON UPDATE CASCADE
  547. );
  548.  
  549. -- inserindo valores na tabela de compra programada
  550.  
  551. INSERT INTO compra_programada ( seq ,id , date_1 , date2 , esta_ativa ) VALUES
  552.  
  553. ( '0001' ,'0002' , '2016-04-09 ' , '2017-04-09 ' , true ),
  554. ('0002' , '0004' , '2016-04-09 ' , '2017-01-09 ' , true ),
  555. ('0003' , '0007' , '2016-04-02 ' , '2016-11-02 ' , true ),
  556. ('0004' ,'0009' , '2016-04-02 ' , '2017-02-02 ' , true ),
  557. ('0005' , '0010' , '2016-04-02 ' , '2017-04-02 ' , true );
  558.  
  559. -- TABELA ITEM DE COMPRA createdyes 13
  560.  
  561. CREATE TABLE item_compra (
  562.  
  563. seq char(4),
  564. cod_compra char(4) not null,
  565. cod_produto char(4) not null,
  566. quantidade int CHECK (quantidade > 0) ,
  567. valor_desconto float default 0 CHECK (valor_desconto >= 0),
  568. valor_unitario float CHECK (valor_unitario > 0),
  569. primary key (seq),
  570. foreign key (cod_compra) references compra (cod)
  571. );
  572.  
  573. -- ITEM COMPRA INCOMPLETO
  574. -- INSERT INTO item_compra ( seq , cod_compra , cod_produto , quantidade , valor_desconto , valor_unitario ) VALUES
  575.  
  576.  
  577. -- TABELA DA MATRIZ xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  578.  
  579. CREATE TABLE matriz (
  580.  
  581. CNPJ char(14),
  582. nomefantasia varchar(10) not null,
  583. primary key (CNPJ)
  584.  
  585. );
  586.  
  587. INSERT INTO matriz( CNPJ , nomefantasia ) VALUES
  588.  
  589. ( '23416393000114' , 'SUPER'),
  590. ( '23416393000140' , 'ICBPE'),
  591. ( '23416393000169' , 'ICBRJ'),
  592. ( '76166587000175' , 'FRUFRU'),
  593. ( '33353657000191' , 'BILU'),
  594. ( '01545535000100' , 'MILU' );
  595. SELECT *
  596. FROM matriz;
  597.  
  598. -- TABELA DE TELEFONE DA MATRIZ xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  599.  
  600. CREATE TABLE telefone_matriz (
  601.  
  602. seq char(4),
  603. CNPJ char(14),
  604. telefone char(10),
  605. primary key (seq),
  606. CONSTRAINT fk_cnpjmatriz foreign key (CNPJ) references matriz (CNPJ) ON DELETE CASCADE ON UPDATE CASCADE
  607.  
  608. );
  609.  
  610. -- inserindo valores na tabela telefone_matriz
  611.  
  612. INSERT INTO telefone_matriz (seq , CNPJ , telefone ) VALUES
  613.  
  614. ('0001' , '23416393000114' , '8133002432'),
  615. ('0002 ', '23416393000140' , '8133002149'),
  616. ('0003' , '23416393000140' , '1133002932'),
  617. ('0004' , '23416393000140' , '1140443949'),
  618. ('0005' , '23416393000169' , '1433004732'),
  619. ( '0006' ,'23416393000169' , '1440002449');
  620.  
  621.  
  622. -- TABELA DE FILIAL xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  623.  
  624. CREATE TABLE filial (
  625.  
  626. seq char(4),
  627. CNPJ_Matriz char(14),
  628. CPF_gerente char(11) ,
  629. endereco varchar(50),
  630. qtd_func int(4) CHECK (qtd_func >= 0),
  631. primary key ( seq ),
  632. CONSTRAINT fk_cnpjmatrizfilial foreign key ( CNPJ_MATRIZ ) references matriz (CNPJ) ON DELETE CASCADE ON UPDATE CASCADE
  633.  
  634.  
  635. );
  636.  
  637. ALTER TABLE filial add constraint foreign key ( CPF_gerente ) references gerente (CPF); -- createdyes 13
  638.  
  639. -- inserindo valores na tabela filial
  640.  
  641. INSERT INTO filial ( seq , CNPJ_Matriz , CPF_gerente , endereco , qtd_func ) VALUES
  642.  
  643. ( '0001' , '23416393000114' , NULL , 'Rua valtavares ' , 4 ),
  644. ( '0002' , '23416393000114' , NULL , 'Rua alivetania ' , 4 ),
  645. ( '0003' , '23416393000140' , NULL, 'Rua maranguape ' , 4 ),
  646. ( '0004' , '23416393000169' , NULL , 'Rua fernigan ' , 4 );
  647.  
  648.  
  649. -- TABELA DE TELEFONE DA FILIAL xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  650.  
  651. CREATE TABLE telefone_filial (
  652.  
  653. seq_filial char(4),
  654. CNPJ_Matriz char(14),
  655. telefone char(10),
  656. primary key (seq_filial),
  657. CONSTRAINT fk_seq foreign key (CNPJ_Matriz) references filial (CNPJ_Matriz) ON DELETE CASCADE ON UPDATE CASCADE
  658.  
  659. );
  660.  
  661. -- inserindo valores na tabela telefone_filial
  662.  
  663. INSERT INTO telefone_filial( seq_filial , CNPJ_Matriz , telefone ) VALUES
  664.  
  665. ( '0001' , '23416393000114' , '1133115021' ),
  666. ( '0002' , '23416393000114' , '1133505231' ),
  667. ( '0003' , '23416393000140' , '8143022151' ),
  668. ( '0004' , '23416393000169' , '1431205412' );
  669.  
  670.  
  671. -- TABELA DE PERDA DE PRODUTO createdyes
  672.  
  673. CREATE TABLE perda (
  674.  
  675. seq char(4),
  676. cod_lote char(4),
  677. cod_produto char(4),
  678. id_estoque char(4),
  679. cpf_gerente char(11) not null,
  680. dia date not null ,
  681. quantidade_perdida int CHECK (quantidade_perdida > 0) ,
  682. motivo varchar(80),
  683. primary key (seq),
  684. key(cod_lote , cod_produto , id_estoque),
  685. foreign key (cpf_gerente) references gerente (cpf),
  686. CONSTRAINT fk_perdaitestoq foreign key (cod_lote, cod_produto , id_estoque ) references item_estoque( cod_lote , id_estoque , cod_produto ) ON DELETE CASCADE ON UPDATE CASCADE
  687.  
  688. );
  689.  
  690. -- INSERT INTO perda ( seq , cod_lote, cod_produto, id_estoque, cpf_gerente , dia , quantidade_perdida , motivo)
  691.  
  692.  
  693. -- TABELA DE VEICULO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  694.  
  695. CREATE TABLE veiculo (
  696.  
  697. placa char(7),
  698. seq_filial char(4) not null,
  699. CNPJ_matriz char(14) not null,
  700. cod_garagem char(4) not null,
  701. modelo varchar(15),
  702. descricao varchar(15),
  703. cor varchar(10),
  704. ano year,
  705. statuss boolean default true,
  706. primary key (placa),
  707. foreign key(seq_filial ) references filial(seq) ,
  708. foreign key (CNPJ_matriz) references filial(CNPJ_Matriz),
  709. foreign key(cod_garagem) references garagem (cod)
  710. );
  711.  
  712. -- inserindo valores na tabela veiculo
  713.  
  714. INSERT INTO veiculo ( placa , seq_filial , CNPJ_matriz , cod_garagem , modelo , descricao , cor , ano , statos ) VALUES
  715.  
  716. ( 'PEX0220 ' , '0001' , '23416393000114' , '0001' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  717. ( 'PEX2030 ' , '0001' , '23416393000114' , '0001' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  718. ( 'VET4320 ' , '0002' , '23416393000114' , '0002' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  719. ( 'VET3240 ' , '0002' , '23416393000114' , '0002' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  720. ( 'WCV0943' , '0003' , '23416393000114' , '0003' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  721. ( 'WCV3344 ' , '0003' , '23416393000114' , '0003' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  722. ( 'HLT0032 ' , '0004' , '23416393000114' , '0004' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  723. ( 'HLT3994 ' , '0004' , '23416393000114' , '0004' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true);
  724.  
  725.  
  726. -- TABELA DE GARAGEM xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  727.  
  728. CREATE TABLE garagem (
  729.  
  730. cod char(4),
  731. seq_filial char(4) not null ,
  732. CNPJ_matriz char(14) not null,
  733. descricao varchar(15),
  734. capacidade int(3) not null,
  735. num_veiculos_atual int(3),
  736. primary key(cod),
  737. foreign key(seq_filial ) references filial (seq),
  738. foreign key (CNPJ_matriz) references filial(CNPJ_matriz)
  739.  
  740.  
  741. );
  742.  
  743. -- inserindo valores na tabela garagem
  744.  
  745. INSERT INTO garagem ( cod , seq_filial , CNPJ_matriz , descricao , capacidade , num_veiculos_atual ) VALUES
  746. ( '0001' , '0001' , '23416393000114' , null , 4 , 2 ),
  747. ( '0002' , '0002' , '23416393000114' , null , 4 , 2 ),
  748. ( '0003' , '0003' , '23416393000140' , null , 4 , 2 ),
  749. ( '0004' , '0004' , '23416393000169' , null , 4 , 2 );
  750.  
  751. SELECT *
  752. FROM garagem;
  753.  
  754. -- TABELA DE ESTOQUE xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  755.  
  756. CREATE TABLE estoque (
  757.  
  758. id char(4),
  759. seq_filial char(7) not null,
  760. cnpj_matriz char(14) not null,
  761. descricao varchar(80),
  762. dt_ultima_entrada date,
  763. primary key (id),
  764. foreign key (seq_filial) references filial (seq),
  765. foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  766.  
  767. );
  768.  
  769.  
  770. -- inserindo valores na tabela estoque
  771.  
  772. INSERT INTO estoque ( id , seq_filial , cnpj_matriz , descricao , dt_ultima_entrada ) VALUES
  773.  
  774. ( '0000001' , '0001' , '23416393000114' , null , '2018-01-04'),
  775. ( '0000002' , '0002' , '23416393000114' , null , '2018-01-04'),
  776. ( '0000003' , '0003' , '23416393000140' , null , '2018-01-04'),
  777. ( '0000004' , '0004' , '23416393000169' , null , '2018-01-04');
  778.  
  779.  
  780. -- TABELA DE LOTE createdyes 13
  781.  
  782. CREATE TABLE lote (
  783.  
  784. cod char(4),
  785. cod_pedido_fornecedor char(4) not null,
  786. descricao varchar(30),
  787. data_chegada date not null,
  788. primary key( cod) ,
  789. foreign key (cod_pedido_fornecedor) references pedido_fornecedor (cod)
  790.  
  791. );
  792.  
  793. -- INSERT INTO lote ( cod, cod_pedido_fornecedor, descricao , data_chegada)
  794.  
  795.  
  796.  
  797. -- TABELA DE ITEM DE ESTOQUE createdyes 13
  798.  
  799. CREATE TABLE item_estoque (
  800.  
  801. seq char(4),
  802. cod_lote char(4),
  803. id_estoque char(4),
  804. cod_produto char(4),
  805. id_avaria char(4) not null,
  806. id_prateleira char(4) not null,
  807. data_validade date not null,
  808. data_fabricacao date not null,
  809. data_entrada date not null,
  810. valor_compra float CHECK (valor_compra > 0),
  811. quantidade int CHECK (quantidade > 0),
  812. primary key (seq),
  813. foreign key (cod_lote) references lote (cod),
  814. foreign key (id_estoque) references estoque (id),
  815. CONSTRAINT fk_produtoestoque foreign key ( cod_produto ) references produto_ref( cod) ON DELETE CASCADE ON UPDATE CASCADE,
  816. foreign key (id_avaria ) references avaria ( id),
  817. foreign key (id_prateleira ) references prateleira ( codigo)
  818.  
  819. );
  820. -- INSERT INTO item_estoque (cod_lote, id_estoque , cod_produto , id_avaria , id_prateleira , data_validade ,
  821. /* data_fabricacao , data_entrada , valor_compra, quantidade)
  822. */
  823.  
  824.  
  825.  
  826. -- TABELA MAQUINA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  827.  
  828. CREATE TABLE maquina (
  829.  
  830. id char(4),
  831. id_estoque char(4) not null,
  832. id_operador char(11) not null,
  833. ano year ,
  834. combustivel varchar(30),
  835. modelo varchar(30),
  836. capacidade float , -- CAPACIDADE EM KG
  837. elevavao_max float , -- ELEVAVAO EM METROS
  838. garantia date,
  839. tipo varchar(30),
  840. comprimento float , -- COMPRIMENTO EM METROS
  841. primary key (id),
  842. foreign key (id_estoque) references estoque (id),
  843. foreign key (id_operador) references estoquista (cpf)
  844. );
  845.  
  846. INSERT INTO maquina ( id , id_estoque , id_operador , ano, combustivel , modelo , capacidade , elevavao_max ,
  847. garantia , tipo , comprimento ) VALUES
  848.  
  849. ( '0001' , '0000001' , '77491222226' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  850. ( '0002' , '0000002' , '57859332507' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  851. ( '0003' , '0000003' , '16565525749' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  852. ( '0004' , '0000004' , '98243208909' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 );
  853.  
  854.  
  855. -- TABELA DE AVARIA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  856.  
  857. CREATE TABLE avaria (
  858.  
  859. id char(4),
  860. causa varchar(20) not null,
  861. preco float(3) CHECK ( preco > 0 ),
  862. obs varchar(40),
  863. primary key(id)
  864.  
  865. );
  866.  
  867. -- inserindo valores na tabela avaria
  868.  
  869. INSERT INTO avaria (id , causa , preco , obs ) VALUES
  870.  
  871. ('0001' , 'Queda' , 30 , null ),
  872. ('0002' , 'Queda' , 10 , null ),
  873. ('0003' , 'Queda' , 200 , null ),
  874. ('0004' , 'Queda' , 32.2 , null ),
  875. ('0005' , 'Queda' , 230 , null ),
  876. ('0006' , 'Queda' , 92.2 , null );
  877.  
  878. -- TABELA DE PRATELEIRA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  879.  
  880. CREATE TABLE prateleira (
  881.  
  882. codigo char(4),
  883. altura float(2) not null,
  884. comprimento float(2) not null,
  885. posicao_nivel char(2),
  886. primary key(codigo)
  887.  
  888. );
  889.  
  890. INSERT INTO prateleira ( codigo , altura , comprimento , posicao_nivel ) VALUES
  891.  
  892. ('0001' , 5 , 10 , 'A1' ),
  893. ('0002' , 5 , 10 , 'A2' ),
  894. ('0003' , 5 , 10 , 'A3' ),
  895. ('0004' , 5 , 10 , 'A4' ),
  896. ('0005' , 5 , 10 , 'A5' ),
  897. ('0006' , 5 , 10 , 'B1' ),
  898. ('0007' , 5 , 10 , 'B2' ),
  899. ('0008' , 5 , 10 , 'B3' ),
  900. ('0009' , 5 , 10 , 'B4' ),
  901. ('0010' , 5 , 10 , 'B5' ),
  902. ('0011' , 5 , 10 , 'C1' ),
  903. ('0012' , 5 , 10 , 'C2' ),
  904. ('0013' , 5 , 10 , 'C3' ),
  905. ('0014' , 5 , 10 , 'C4' ),
  906. ('0015' , 5 , 10 , 'C5' );
  907.  
  908. -- TABELA DE NCM DE PRODUTO createdyes 13
  909.  
  910. CREATE TABLE NCM (
  911.  
  912. id char(4),
  913. descricao varchar(40),
  914. cod_mercosul char(9) not null,
  915. primary key(id)
  916.  
  917. );
  918.  
  919. INSERT INTO NCM ( id , descricao , cod_mercosul) VALUES
  920.  
  921. ('0001', ' ' , '000000001'),
  922. ('0002' , ' ' , '000000002'),
  923. ('0003' , ' ', '000000003'),
  924. ('0004' , ' ', '000000004'),
  925. ('0005', ' ' , '000000005');
  926.  
  927. -- TABELA DE UNIDADE DE PRODUTO createdyes 13
  928.  
  929. CREATE TABLE unidade (
  930.  
  931. cod char(4),
  932. descricao varchar(30),
  933. sigla char(2) not null,
  934. primary key(cod)
  935.  
  936.  
  937. );
  938.  
  939. INSERT INTO unidade (cod, descricao , sigla) VALUES
  940.  
  941. ('0001', 'quilogramas', 'kg'),
  942. ('0002' , 'mililitros', 'mL'),
  943. ('0003', 'gramas' , 'g'),
  944. ('0004', 'litros' , 'L'),
  945. ('0005', 'miligramas' , 'mg');
  946.  
  947.  
  948. -- TABELA DE CATEGORIA DE PRODUTO createdyes 13
  949.  
  950. CREATE TABLE categoria (
  951.  
  952. cod char(4),
  953. descricao varchar(30) not null,
  954. primary key (cod)
  955.  
  956. );
  957.  
  958. INSERT INTO categoria ( cod , desricao ) VALUES
  959.  
  960. ('0001', 'Condimentos' ),
  961. ('0002' , 'Laticinios'),
  962. ('0003', 'HortiFruti'),
  963. ('0004' , 'Conservas'),
  964. ('0005', 'Limpeza'),
  965. ('0006' , 'Bebidas Alcoolicas'),
  966. ('0007' , 'Bebidas nao Alcoolicas'),
  967. ('0008' , 'Graos e Cereais');
  968.  
  969. -- TABELA DE SUBCATEGORIA DE PRODUTO createdyes 13
  970.  
  971. CREATE TABLE subcategoria (
  972.  
  973. cod char(4),
  974. cod_categoria char(4) not null,
  975. descricao varchar(30) not null,
  976. primary key(cod),
  977. foreign key (cod_categoria) references categoria(cod)
  978.  
  979. );
  980.  
  981. INSERT INTO subcategoria ( cod , cod_categoria , descricao ) VALUES
  982.  
  983. ('0001' , '0001' , 'Vinagres'),
  984. ('0002' , '0001' , 'Temperos'),
  985. ('0003' , '0001' , 'Sal' ),
  986. ('0004' , '0001', 'Azeites'),
  987. ('0005' , '0001', 'Oleos'),
  988. ('0006' , '0001', 'Especiarias'),
  989. ('0007' , '0002', 'Leites'),
  990. ('0008' , '0002', 'Iogurtes'),
  991. ('0009' , '0002', 'Fermentados'),
  992. ('0010' , '0002', 'Queijos'),
  993. ('0011' , '0003', 'Ovos'),
  994. ('0012' , '0003', 'Frutas secas'),
  995. ('0013' , '0003', 'Legumes'),
  996. ('0014' , '0004' , 'Frutas'),
  997. ('0015' , '0004', 'Peixes'),
  998. ('0016' , '0004', 'Vegetais'),
  999. ('0017' , '0004', 'Cogumelos'),
  1000. ('0018' , '0005', 'Detergente'),
  1001. ('0019' , '0005', 'Desinfetante'),
  1002. ('0020' , '0005', 'Sabao em po'),
  1003. ('0021' , '0005', 'Sabao em barra'),
  1004. ('0022' , '0005', 'Amaciante');
  1005.  
  1006.  
  1007. -- TABELA DE MARCA DE PRODUTO createdyes 13
  1008.  
  1009. CREATE TABLE marca (
  1010.  
  1011. cod char(4),
  1012. descricao varchar(40),
  1013. primary key(cod)
  1014.  
  1015. );
  1016.  
  1017. INSERT INTO marca ( cod , descricao ) VALUES
  1018.  
  1019. ('0001', 'Sadia'),
  1020. ('0002' , 'Knorr'),
  1021. ('0004' , 'Camponesa'),
  1022. ('0005' , 'Kicaldo'),
  1023. ('0006' , 'Vitarela'),
  1024. ('0007' , 'Bauduco'),
  1025. ('0008', 'OMO'),
  1026. ('0009' , 'Dona Benta'),
  1027. ('0010', 'Nestle');
  1028.  
  1029.  
  1030. -- TABELA DE FORNECEDOR xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1031.  
  1032. CREATE TABLE fornecedor (
  1033.  
  1034. cod char(4),
  1035. nome varchar(20) not null,
  1036. CNPJ char(14) not null,
  1037. rua varchar(20),
  1038. bairro varchar(15),
  1039. CEP char(8),
  1040. estado varchar(15) not null,
  1041. ativo boolean default true,
  1042. primary key(cod)
  1043. );
  1044.  
  1045. -- inserindo valores na tabela fornecedor
  1046.  
  1047. INSERT INTO fornecedor ( cod , nome , CNPJ , rua , bairro , CEP , estado , ativo ) VALUES
  1048.  
  1049. ('0001' , 'Sadia' , '55274471000180' , 'Rua valadares ' , 'ipsep ', '54330315' , 'Pernambuco' , true ) ,
  1050. ('0002' , 'Pampers' , '26724671000180' , 'Rua cartomante ' , 'ibura', '54202010' , 'Pernambuco' , true ) ,
  1051. ('0003' , 'Vitarela' , '21712241000162' , 'Rua maniac ' , 'algodão', '54215322' , 'São paulo' , true ) ,
  1052. ('0004' , 'Coca-cola' , '26804531000180' , 'Rua argola ' , 'vale tinhaem ', '51215020' , 'Rio de janeiro' , true ) ,
  1053. ('0005' , 'Helmans' , '77411981000180' , 'Rua sartre ' , 'gitacity ', '44650201' , 'São paulo' , true ),
  1054. ('0006' , 'Bombril' , '53686527000188' , 'Avenida Afonso Olindense' , 'Varzea' , '50980320' , 'Recife' , true );
  1055.  
  1056.  
  1057. -- TABELA DE TELEFONE DE FORNECEDOR xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1058.  
  1059. CREATE TABLE telefone_fornecedor(
  1060.  
  1061. seq char(4) ,
  1062. cod_fornecedor char(4),
  1063. telefone char(11),
  1064. primary key(seq),
  1065. CONSTRAINT fk_forn foreign key(cod_fornecedor) references fornecedor (cod) ON DELETE CASCADE ON UPDATE CASCADE
  1066.  
  1067. );
  1068.  
  1069. -- inserindo valores na tabela telefone_fornecedor
  1070.  
  1071. INSERT INTO telefone_fornecedor ( seq , cod_fornecedor,telefone) VALUES
  1072.  
  1073. ('0001' ,'0001' , '8133115544'),
  1074. ('0002' ,'0002' , '8133468952'),
  1075. ('0003' ,'0003' , '1140025632'),
  1076. ('0004' ,'0004', '1432456895'),
  1077. ('0005' , '0005', '1121452062');
  1078.  
  1079. -- TABELA DE PRODUTO REF createdyes 13
  1080.  
  1081. CREATE TABLE produto_ref (
  1082.  
  1083. cod char(4),
  1084. id_unidade char(4),
  1085. id_marca char(4),
  1086. id_ncm char(4),
  1087. id_categoria char(4),
  1088. id_subcategoria char(4),
  1089. id_fornecedor char(4),
  1090. qtd_estoque int ,
  1091. ICMS float,
  1092. CST char(3),
  1093. preco_por_tabela float,
  1094. cod_barra char(13),
  1095. freq_pedido float,
  1096. descricao varchar(30),
  1097. qtd_min int,
  1098. qtd_total_estoque int,
  1099. preco_ult_compra float,
  1100. primary key (cod),
  1101. foreign key (id_unidade) references unidade (cod),
  1102. foreign key (id_marca) references marca (cod),
  1103. foreign key (id_ncm) references ncm (id),
  1104. foreign key (id_categoria) references categoria (cod),
  1105. foreign key (id_subcategoria) references subcategoria (cod),
  1106. foreign key (id_fornecedor) references fornecedor (cod)
  1107.  
  1108. );
  1109.  
  1110. -- INSERT INTO profuto_ref (cod, id_unidade , id_marca , id_ncm , id_categoria, id_subcategoria, id_fornecedor , qtd_estoque ,
  1111. /* ICMS , CST , preco_por_tabela , cod_barra , freq_pedido , descricao , qtd_min, qtd_total_estoque , preco_ult_compra)
  1112. */
  1113.  
  1114. -- TABELA DE INCIDENTE xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1115.  
  1116. CREATE TABLE incidente (
  1117.  
  1118. cod char(4),
  1119. seq_entrega char(4) not null,
  1120. dataa date not null,
  1121. relatorio varchar(200),
  1122. hora time not null,
  1123. primary key(cod),
  1124. foreign key ( seq_entrega) references entrega (seq)
  1125.  
  1126. );
  1127.  
  1128. -- inserindo valores na tabela incidente
  1129.  
  1130. INSERT INTO incidente (cod , seq_entrega , dataa, relatorio , hora ) VALUES
  1131.  
  1132. ('0001' , '0003' , '2016-04-09 ' , ' Tentativa de assalto ' , '18:06:00' ),
  1133. ('0002' , '0005' , '2016-04-09 ' , ' Tentativa de assalto ' , '13:34:00' ),
  1134. ('0003' , '0006' , '2016-04-02 ' , ' Tentativa de assalto ' , '06:32:00' );
  1135.  
  1136. -- TABELA DOCS xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1137.  
  1138. CREATE TABLE docs (
  1139.  
  1140. seq char(4),
  1141. cod_incidente char(4),
  1142. docs varchar(20),
  1143. primary key (seq),
  1144. CONSTRAINT fk_incidente foreign key (cod_incidente) references incidente (cod ) ON DELETE CASCADE ON UPDATE CASCADE
  1145. );
  1146.  
  1147. -- inserindo valores na tabela docs
  1148.  
  1149. INSERT INTO docs ( seq ,cod_incidente , docs ) VALUES
  1150.  
  1151. ('0001' , '0001', null ) ,
  1152. ('0002' ,'0002' , null ) ,
  1153. ('0003' ,'0003' , null);
  1154.  
  1155. -- TABELA DE PAGAMENTO createdyes 13
  1156.  
  1157. CREATE TABLE pagamento (
  1158.  
  1159. cod char(4),
  1160. id_fatura char(4) not null,
  1161. cod_compra char(4) not null,
  1162. cod_tipo_pagamento char(4) not null,
  1163. valor_pago float CHECK ( valor_pago > 0 ),
  1164. dia date not null,
  1165. statos boolean default true ,
  1166. tipo_pagamento enum ('Cartao credito', 'Cartao Debito', 'Boleto'),
  1167. primary key (cod),
  1168. foreign key (id_fatura) references fatura (id),
  1169. foreign key (cod_compra) references compra (cod),
  1170. foreign key (cod_tipo_pagamento) references tipo_pagamento ( cod)
  1171.  
  1172. );
  1173. -- INSERT INTO pagamento ( cod, id_fatura ,cod_compra , cod_tipo_pagamento , valor_pago , dia , statos, tipo_pagamento ) VALUES
  1174.  
  1175. -- TABELA DE TIPO DE PAGAMENTO createdyes OK 13
  1176.  
  1177. CREATE TABLE tipo_pagamento (
  1178.  
  1179. cod char(4),
  1180. descricao varchar(30),
  1181. primary key(cod)
  1182.  
  1183. );
  1184.  
  1185. INSERT INTO tipo_pagamento (cod, descricao ) VALUES
  1186. ('0001' , 'Boleto Bancario'),
  1187. ('0002' , 'Cartao de Credito'),
  1188. ('0003' , 'Cartao de Debito');
  1189.  
  1190.  
  1191. -- TABELA DE FATURA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1192.  
  1193. CREATE TABLE fatura (
  1194.  
  1195. id char(4),
  1196. cod_pedido_fornecedor char(4),
  1197. data_vencimento date not null,
  1198. valor_pago_atual float CHECK (valor_pago_atual > 0 ),
  1199. valor_total_final float CHECK (valor_total_final > 0),
  1200. data_emissao date not null,
  1201. statos boolean default true,
  1202. data_paga date,
  1203. multa float,
  1204. primary key (id),
  1205. foreign key (cod_pedido_fornecedor) references pedido_fornecedor (cod)
  1206.  
  1207. );
  1208.  
  1209.  
  1210. -- TABELA DE NOTA FISCAL createdyes 13
  1211.  
  1212. CREATE TABLE nota_fiscal (
  1213.  
  1214. NFE char(9),
  1215. ICMS float not null,
  1216. valor_total float not null CHECK ( valor_total > 0 ),
  1217. valor_total_desconto float CHECK ( valor_total_desconto >= 0 ),
  1218. dia date not null,
  1219. valor_frete float,
  1220. primary key (NFE)
  1221. );
  1222.  
  1223. INSERT INTO nota_fiscal (NFE , ICMS , valor_total, valor_total_desconto, dia , valor_frete) VALUES
  1224.  
  1225. ('111111109' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1226. ('111111104' , NULL , 35.80 , 35.80, '2017-10-21' , 7.90),
  1227. ('111111105' , NULL , 50.21 , 49.95 , '2012-03-27' , 10.32),
  1228. ('111111105' , NULL , 173.98, 173.98 , '2010-06-13' , 8.50),
  1229. ('111111107' , NULL , 50.43 , 50.43 , '2002-04-01' , 2.21),
  1230. ('111111108' , NULL , 283,10 , 279.50 , '2011-11-11' , 4.30),
  1231. ('111111139' , NULL , 123.54 , 111.20 , '2016-11-12' , 6.80),
  1232. ('111111199' , NULL , 12.99 , 12.99 , '2016-11-13' , 8.30),
  1233. ('111111129' , NULL , 346.10 , 336.10 , '2016-11-10' , 2.12);
  1234.  
  1235. -- TABELA DA NOTA FISCAL FORNECEDOR createdyes 13
  1236.  
  1237. CREATE TABLE nota_fiscal_fornecedor (
  1238.  
  1239. NFE char(9),
  1240. cod_pagamento char(4) not null,
  1241. CFOP char(8) not null,
  1242. IPI float,
  1243. primary key(NFE),
  1244. CONSTRAINT fk_ntfiscalfornecedor foreign key (NFE) references nota_fiscal (NFE) ON DELETE CASCADE ON UPDATE CASCADE,
  1245. foreign key (cod_pagamento) references pagamento (cod)
  1246. );
  1247.  
  1248. -- NOTA FISCAL FORNEEDOR INCOMPLETO
  1249. INSERT INTO nota_fiscal_fornecedor (NFE, cod_pagamento , CFOP , IPI ) VALUES
  1250.  
  1251. ('111111109' , NULL , 143.98 , 120 , '2016-11-12' , 3.78),
  1252. ('111111104' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1253. ('111111105' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1254. ('111111145' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1255. ('111111184' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1256. ('111111110' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1257. ('111111133' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1258. ('111111199' , NULL , 143.98 , 139.90 , '2016-11-12' , 3.78);
  1259.  
  1260. -- TABELA NOTA FISCAL COMPRA createdyes 13
  1261.  
  1262. CREATE TABLE nota_fiscal_compra (
  1263.  
  1264. NFE char(9),
  1265. cod_pagamento char(4),
  1266. primary key (NFE),
  1267. CONSTRAINT fk_ntfiscalcompra foreign key (NFE) references nota_fiscal (NFE) ON DELETE CASCADE ON UPDATE CASCADE,
  1268. foreign key (cod_pagamento) references pagamento (cod)
  1269.  
  1270. );
  1271.  
  1272. -- TABELA DE CLIENTE createdyes 13
  1273.  
  1274. CREATE TABLE cliente (
  1275.  
  1276. CPF char(11),
  1277. seq_filial char(4) not null,
  1278. cnpj_matriz char(14) not null,
  1279. cep char(8) not null,
  1280. cidade varchar(30),
  1281. numero char(11),
  1282. descricao varchar(30),
  1283. valor_credito float,
  1284. p_nome varchar(20) not null,
  1285. m_nome varchar(20) ,
  1286. u_nome varchar(30) not null,
  1287. rg char(7) not null,
  1288. senha varchar(12) not null default '123456',
  1289. tem_clube_desconto boolean default false,
  1290. data_cadastro date,
  1291. email varchar(40) not null,
  1292. data_nascimento date not null,
  1293. primary key (CPF),
  1294. foreign key (seq_filial) references filial (seq ),
  1295. foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  1296.  
  1297. );
  1298.  
  1299. INSERT INTO cliente ( CPF , seq_filial , cep, cidade, numero, descricao , valor_credito, p_nome , m_nome , u_nome, rg , senha , tem_clube_desconto , data_cadastro , email , data_nascimento) VALUES
  1300.  
  1301. ('54501233290' , '0001' , '52291045' , 'Recife' , 13 , 'Rua Jaguaribara' , 1200.00 , 'Melissa' , 'Andreia' , 'Nascimento', '1908234', false , '2016-02-12', 'manasc@gmail.com' , '1999-06-13'),
  1302. ('25251145314' , '0002' , '50999321' , 'Olinda' , 11 , 'Rua de Saão Bento' , 0 , 'Marcos' , 'Andre' , 'Marques' , '9123786' , 'xxx9' , false , '2015-03-11' , 'marcossantos@hotmail.com' , '1980-03-25' ),
  1303. ('13345509287' , '0001' , '50348567' , 'Recife' , 320 , 'Rua Real da Torre ' , 0, 'Fatima' , 'Caixias' , 'Laffaiete' , '1866630' , '1233' , false , '2017-02-11' , 'falcaix@gmail.com' , '1972-09-09'),
  1304. ('77658476358' , '0001' , '63900435' , 'Ceará' , 618 , 'Rua Chile' , 0 , 'Renato' , 'Murilo' , 'Dias' , '1266839' , '34g4' , false , '2017-07-04', 'murilodias@gmail.com' , '1989-12-29'),
  1305. ('50519774647' , '0002' , '56332078' , 'Petrolina' , 275 , 'Rua Quarenta e Seis' , 22.30 , 'Joaquim', 'Luiz' , 'Campos' , '287101988' , '88uh' , true , '2016-04-04' , 'uizjoaquim@hotmail.com' , '1990-04-30'),
  1306. ('79317880797' , '0001' , '82600130' , 'Curitiba' , 552 , 'Rua Bernardo Rosenmann' , 0, 'Alana' , 'Rodrigues', 'Mello', '2368088' , '34f4' , true , '2016-09-11' , 'alana_rodriques@gmail.com' , '1993-06-06'),
  1307. ('52125191105' , '0002' , '77820026' , 'Araguaina' , 944, 'Rua 16' , 0, 'Luana', 'Barbosa' , 'Pinto' , '1994566' , '9jf4' , true , '2016-09-11' , 'luaninha_babrbosa@gmail.com' , '1996-06-06'),
  1308. ('50130428361' , '0001' , '77016638' , 'Palmas' , 763 , 'Quadra 509 Sul Alameda 7' , 0, 'Agatha', 'Vasconcelos' , 'Belarmino' , '4526174' , 'f56g' , true , '2016-03-04', 'agatinha_bb@gmail.com' , '1999-09-09'),
  1309. ('96468793068' , '0001' , '49069186' , 'Aracaju', 988, 'Rua do Sol' , 0 , 'Camila' , 'Castro' , 'Raimundo' , '3199788' , 'kj004' , true , '2016-09-18', 'camila_racastro@gmail.com' , '1992-02-20'),
  1310. ('16512268903' , '0002', '72876134' , 'Valparaíso de Goiás' , 588 , 'Quadra 37' , 23.33, 'Valkiria' , 'Queiroz' , 'Calado' , '4241822' , 'kd3io4' , true , '2016-02-12' , 'valqueiros@outlook.com' , '1960-03-07'),
  1311. ('07617589689' , '0002' , '89280577' , 'São Bento do Sul' , 124 , 'Rua Zanzibar' , 0, 'Angelica' , 'Meneses' , 'da Silva' , '4764955' , 'i4hfi4h' , false , '2017-02-05' , 'angelica_mene@outlook.com' , '1992-12-11');
  1312.  
  1313.  
  1314. -- TABELA DE TELEFONE DE CLIENTE createdyes 13
  1315.  
  1316. CREATE TABLE telefone_cliente (
  1317.  
  1318. CPF char(11) not null,
  1319. telefone char(10),
  1320. primary key (telefone),
  1321. CONSTRAINT fk_telefonecliente foreign key (CPF) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1322. );
  1323.  
  1324. INSERT INTO telefone_cliente ( CPF, telefone) VALUES
  1325.  
  1326. ('54501233290' , '8134564432'),
  1327. ('25251145314' , '8199890765'),
  1328. ('77658476358' , '8599690359'),
  1329. ('07617589689' , '4899097820'),
  1330. ('07617589689' , '8191913012'),
  1331. ('96468793068' , '7934876650'),
  1332. ('96468793068' , '7988786534'),
  1333. ('50519774647' , '8133234567');
  1334.  
  1335.  
  1336. -- TABELA DE SUGESTAO createdyes 13
  1337.  
  1338. CREATE TABLE sugestao (
  1339.  
  1340. CPF_cliente char(11) not null,
  1341. id char(4),
  1342. dia date,
  1343. descricao varchar(30) not null,
  1344. primary key (id),
  1345. CONSTRAINT fk_sugestao foreign key (CPF_cliente) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1346. );
  1347.  
  1348. INSERT INTO sugestao (CPF_cliente, id, dia , descricao) VALUES
  1349.  
  1350. ('54501233290' , '0001' , '2016-02-12' , 'mais entregadores'),
  1351. ('54501233290' , '0002' , '2016-03-09' , 'mais entregadores'),
  1352. ('54501233290' , '0003' , '2016-03-09' , 'mais entregadores'),
  1353. ('54501233290' , '0004' , '2016-03-09' , 'mais entregadores'),
  1354. ('54501233290' , '0005' , '2016-03-09' , 'mais entregadores'),
  1355. ('54501233290' , '0006' , '2016-03-09' , 'mais entregadores'),
  1356. ('54501233290' , '0007' , '2016-03-09' , 'mais entregadores'),
  1357. ('54501233290' , '0008' , '2016-03-09' , 'mais entregadores'),
  1358. ('54501233290' , '0009' , '2016-03-09' , 'mais entregadores');
  1359.  
  1360.  
  1361. -- TABELA DE RECLAMACAO createdyes 13
  1362.  
  1363. CREATE TABLE reclamacao (
  1364.  
  1365. CPF_cliente char(11) not null,
  1366. id char(4),
  1367. descricao varchar(30) not null,
  1368. motivo varchar(20),
  1369. data_ocorrido date not null,
  1370. data_reclamacao date,
  1371. primary key (id),
  1372. CONSTRAINT fk_reclamacao foreign key (CPF_cliente) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1373. );
  1374.  
  1375. INSERT INTO reclamacao ( CPF_cliente , id , motivo, data_ocorrido, data_reclamacao) VALUES
  1376.  
  1377. ('54501233290' , '0001' , 'atendimento muito demorado', '2016-03-09' , '2016-03-13'),
  1378. ('54501233290' , '0002' , 'produto estava perto de vencer', '2016-03-09' , '2016-03-13'),
  1379. ('54501233290' , '0003' , 'o entregador nao chegou', '2016-03-01' , '2016-03-20'),
  1380. ('54501233290' , '0004' , 'erraram o endereco de entrega', '2016-03-09' , '2016-03-13'),
  1381. ('54501233290' , '0005' , 'atendimento muito demorado', '2016-03-09' , '2016-03-10'),
  1382. ('54501233290' , '0006' , 'site fora do ar', '2016-04-01' , '2016-04-01'),
  1383. ('54501233290' , '0007' , 'atendimento muito demorado', '2016-03-09' , '2016-03-13');
  1384.  
  1385.  
  1386. -- TABELA DE PROMOCAO createdyes 13
  1387.  
  1388. CREATE TABLE promocao (
  1389.  
  1390. cod char(4),
  1391. seq_filial char(4) not null,
  1392. cnpj_matriz char(14) not null,
  1393. nome varchar(30),
  1394. data_inicio date not null,
  1395. percentual_reducao float not null CHECK ( percentual_reducao > 0 ),
  1396. data_fim date,
  1397. obs varchar(30),
  1398. descricao varchar(50),
  1399. primary key (cod),
  1400. foreign key (seq_filial ) references filial (seq),
  1401. foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  1402. );
  1403.  
  1404. INSERT INTO promocao (cod, seq_filial , nome , data_inicio, percentual_reducao , data_fim, obs, descricao) VALUES
  1405.  
  1406. ('0001' , '0001 ', 'Um barato no pedaco' , '2017-02-05', 0.13 , '2017-03-05' , 'nao inclui produtos importados' , ' promocao para o setor de laticinios'),
  1407. ('0002' , '0001' , 'Queima de estoque' , '2016-12-22' , 0.33 , '2016-12-31' , NULL , NULL),
  1408. ('0003' , '0002', 'Mes da verdura' , '2017-08-12' , 0.26 , '2017-10-12' , 'nao inclui o setor de conservas' , 'promocao para o setor de hortifruti' ),
  1409. ('0004' , '0002' , 'Mes da conserva' , '2017-11-20' , 0.21 , '2017-12-20', NULL , 'apenas para as conservas' ),
  1410. ('0005 ', '0001' , 'Desinfetantes em queima' , '2018-01-02' , 0.24 , '2018-02-02' , NULL , 'apenas para os desinfetantes'),
  1411. ('0006' , '0002' , 'Promocao de amaciante' , '2017-09-15' , 0.12, '2017-11-15' , NULL , 'promocao de amaciantes nacionais'),
  1412. ('0007' , '0001' , 'Laticinios vao a loucura' , '2018-01-02', 0.29, '2018-03-02' , NULL , 'reducao de preco nos laticinios'),
  1413. ('0008' , '0002' , 'Promocao de Sabao em po' , '2017-06-15' , 0.19 , '2017-07-15' , NULL , 'promocao para sabao em po');
  1414.  
  1415. -- TABELA DE PEDIDO FORNECEDOR createdyes 13
  1416.  
  1417. CREATE TABLE pedido_fornecedor (
  1418.  
  1419. cod char(4),
  1420. CPF_gerente char(11) not null,
  1421. total_desconto float CHECK ( total_desconto >= 0 ),
  1422. valor_total_IPI float CHECK ( valor_total_IPI >= 0 ),
  1423. CFOP char(4) not null,
  1424. valor_total float CHECK ( valor_total >= 0),
  1425. dia date not null,
  1426. statos boolean default true,
  1427. valor_frete float CHECK (valor_frete >= 0),
  1428. primary key (cod),
  1429. foreign key (CPF_gerente) references gerente (CPF)
  1430. );
  1431.  
  1432. INSERT INTO pedido_fornecedor ( cod, CPF_gerente , total_desconto , valor_total_IPI, dia , statos, valor_frete ) VALUES
  1433.  
  1434. ('0001' , '96202875763' , 12380.00, 354.20 , '2017-12-09' , true , 12.90),
  1435. ('0002', '96202875763' , 3456.40 , 123.20 , '2017-11-09' , true , 10.30),
  1436. ('0003' , '96202875763' , 2280.25 , 220.00, '2017-06-13', true , 28.50),
  1437. ('0004' , '96202875763' , 12200.00, 123.99, '2017-07-04', true , 9.89),
  1438. ('0005' , '96202875763' , 990.00 , 19.89, '2016-12-09', true , 12.43),
  1439. ('0006' , '96202875763' , 5660.00, 56.70 , '2015-08-27' , true , 6.98),
  1440. ('0007' , '96202875763' , 2890.00 , 35.47 , '2016-04-12' , true , 10.20),
  1441. ('0008' , '96202875763' , 1873.20 , 190.00 , '2017-01-04' , true , 8.33),
  1442. ('0009' , '96202875763' , 2348.80, 111.10 , '2017-06-09' , true , 10.22),
  1443. ('0010' , '02123011878' , 1300.00, 132.30 , '2017-08-27' , true , 11.30);
  1444.  
  1445. -- TABELA DE ITEM PEDIDO createdyes 13
  1446.  
  1447. CREATE TABLE item_pedido (
  1448.  
  1449. seq char(4),
  1450. cod_produto_ref char(4) not null,
  1451. cod_pedido_fornecedor char(4) not null,
  1452. quantidade int not null CHECK (quantidade > 0) ,
  1453. preco_unitario float not null CHECK (preco_unitario > 0),
  1454. primary key (seq),
  1455. foreign key (cod_produto_ref) references produto_ref (cod),
  1456. foreign key (cod_pedido_fornecedor) references pedido_fornecedor(cod)
  1457. );
  1458.  
  1459. -- INSERT INTO item_pedido (seq , cod_produto_ref , cod_pedido_fornecedor, quantidade , preco_unitario) VALUES
  1460.  
  1461.  
  1462. -- TABELA DE RELACIONAMENTO TEM DE FUNCIONARIO createdyes 13
  1463.  
  1464. CREATE TABLE tem (
  1465.  
  1466. seq char(4),
  1467. id_jornada char(4),
  1468. id_turno char(4),
  1469. id_dia char(4),
  1470. primary key (seq),
  1471. foreign key (id_jornada) references jornadatrabalho(id),
  1472. foreign key (id_turno) references turno(cod),
  1473. foreign key (id_dia) references dia (sequencial)
  1474.  
  1475. );
  1476.  
  1477.  
  1478. -- INSERT INTO tem (id_jornada , id_turno, id_dia ) VALUES
  1479.  
  1480. -- TABELA RELACIONAMENTO REALIZA CURSO createdyes 13
  1481.  
  1482. CREATE TABLE realizacurso (
  1483.  
  1484. seq char(4),
  1485. cpf_fun char(11),
  1486. id_curso char(4),
  1487. dt_inicio date,
  1488. dt_fim date,
  1489. primary key (seq),
  1490. foreign key (cpf_fun) references funcionario(CPF),
  1491. foreign key (id_curso) references curso (id)
  1492. );
  1493.  
  1494. INSERT INTO realizacurso ( seq , cpf_fun , id_curso , dt_inicio , dt_fim) VALUES
  1495.  
  1496. ('0001','77491222226', '2101' , '2016-02-13' , '2016-03-15' ),
  1497. ('0002', '77491222226' , '8012' , '2016-04-09' , '2016-06-09' ),
  1498. ('0003', '32568071001' , '2101' ,'2016-02-13' , '2016-03-15' ),
  1499. ('0004', '45321186898' , '8012' , '2016-04-09' , '2016-06-09' ),
  1500. ('0005', '77491222226' , '8012' , '2016-04-09' , '2016-06-09' ),
  1501. ('0006' ,'14073416260' , '8012' , '2016-04-09' , '2016-06-09' ),
  1502. ('0007', '88356795591' , '8012' , '2016-04-09' , '2016-06-09' );
  1503.  
  1504. -- TABELA DE GERENCIA DE ESTOQUE/* createdyes 13
  1505.  
  1506. CREATE TABLE gerencia_estoque (
  1507.  
  1508. seq char(4),
  1509. cpf_super_estoque char(11),
  1510. id_estoque char(4),
  1511. dt_fim date,
  1512. dt_inicio date,
  1513. primary key (seq),
  1514. foreign key (cpf_super_estoque) references SupervisorEstoque (CPF),
  1515. foreign key (id_estoque) references estoque(id)
  1516.  
  1517. );
  1518.  
  1519. SELECT *
  1520. FROM gerencia_estoque;
  1521.  
  1522. INSERT INTO gerencia_estoque (seq, cpf_super_estoque, id_estoque , dt_fim, dt_inicio) VALUES
  1523.  
  1524. ('0001' ,'14073416260' , '0000001' ,'2017-03-02' ,'2016-03-02'),
  1525. ('0002', '85902755239' , '0000002' , '2017-04-15' , '2016-02-15'),
  1526. ('0003', '88356795591' , '0000003' , '2016-01-01' , '2014-02-13'),
  1527. ('0004', '14073416260' , '0000002 ' , '2013-06-22' , '2012-06-10'),
  1528. ('0005', '85902755239' , '0000003' ,'2017-09-02', '2016-01-02' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement