Advertisement
LeoMonte

part 2 completa

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