11eimilia11

ten four

Jan 7th, 2018
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 53.69 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 OK
  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 OK
  92.  
  93. INSERT INTO estoquista (seq ,CPF) VALUES
  94.  
  95. ('0001', '77491222226'),
  96. ('0002' ,'98243208909'),
  97. ('0003' ,'57859332507'),
  98. ('0004','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 OK
  111.  
  112. INSERT INTO DBA (seq , CPF) VALUES
  113.  
  114. ('0001' ,'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 OK
  128.  
  129. INSERT INTO gerente (seq , CPF) VALUES
  130.  
  131. ('0001', '96202875763'),
  132. ('0002','02123011878'),
  133. ('0003','15141182894'),
  134. ('0004','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 OK
  148.  
  149. INSERT INTO entregador (seq , CPF) VALUES
  150. ('0001', '33666472214'),
  151. ('0002', '86147207504'),
  152. ('0003','32970753502'),
  153. ('0004','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 OK
  166.  
  167. INSERT INTO supervisorestoque (seq , CPF) VALUES
  168.  
  169. ('0001' ,'14073416260'),
  170. ('0002', '85902755239' ),
  171. ('0003', '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 OK
  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 OK
  215.  
  216. INSERT INTO notificacao (id, cpf_fun, dia, descricao) VALUES
  217.  
  218. ('2940' , '33666472214' , '2014-02-26' , 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-12' , 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-10' , 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 OK
  247.  
  248. INSERT INTO notif_multa (seq, id , pontos_cnh, 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 OK
  268.  
  269. INSERT INTO notif_advertencia (seq , id, descricao ) VALUES
  270. ('0001' ,'2943' , NULL),
  271. ('0002' , '2944' , NULL),
  272. ('0003' ,'2945' , NULL);
  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 OK
  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 OK
  308.  
  309. INSERT INTO notif_falta (seq , id , dia , duracao ) VALUES
  310.  
  311. ('0001' ,'2949' , '2015-06-01' , 3),
  312. ('0002','2950' , '2015-08-19' , 2 ),
  313. ('0003' ,'2951' , '2015-09-09' , 2);
  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 OK
  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.     seq char(4),
  346.     mes_referencia char(2) CHECK( mes_referencia > 0 AND mes_referencia < 13 ),
  347.     CPF char(11) not null,
  348.     data_pagamento date not null,
  349.     valor_bruto float(5) not null,
  350.     valor_liqd float(5) not null,
  351.     valor_desconto float(5),
  352.     primary key (seq),
  353.     foreign key(CPF) references funcionario(CPF)
  354.  
  355. );
  356.  
  357.  
  358. -- inserindo valores na tabela contracheque OK
  359.  
  360. INSERT INTO contracheque (seq ,mes_referencia , CPF, data_pagamento , valor_bruto, valor_liqd, valor_desconto) VALUES
  361.  
  362. ('0001' ,'02', '96202875763' , '2017-02-15', 3250.30, 3237.68 , 12.32),
  363. ('0002' , '03' , '96202875763', '2017-03-15' , 3250.30,  3237.68, 12.32),
  364. ('0003', '05' , '45321186898' , '2017-05-15' , 8720.55,8708.8, 11.75),
  365. ('0004','01' , '57325297050' , '2017-01-15' , 5956.00, 5942.00 , 14.00),
  366. ('0005','03' , '85902755239' ,'2017-03-15', 4567.32 , 4553.32 , 14.00),
  367. ('0006','08' , '85902755239' , '2017-08-15',4567.32 , 4553.32 , 14.00),
  368. ('0007','01', '96202875763' , '2017-01-15', 3250.30, 3237.68 , 12.32),
  369. ('0008','11' , '45321186898' , '2017-11-15' , 8720.55,8708.8, 11.75),
  370. ('0009','07' , '45321186898' , '2017-07-15' , 8720.55,8708.8, 11.75),
  371. ('0010','04' , '45321186898' , '2017-04-15' , 8720.55,8708.8, 11.75),
  372. ('0011','04' , '02123011878' , '2017-04-15' ,4567.32 , 4553.32, 14.00),
  373. ('0012','05' ,'86147207504', '2016-05-16' , 3250.30, 3237.68 , 12.32);
  374.  
  375. -- TABELA DE JORNADA DE TRABALHO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  376.  
  377. CREATE TABLE jornadatrabalho (
  378.    
  379.     id char(4) ,
  380.     descricao varchar(60),
  381.     trabalha_sabado boolean not null default true,
  382.     primary key(id)
  383.  
  384. );
  385.  
  386. -- inserindo valores na tabela jornadatrabalho OK
  387.  
  388. INSERT INTO jornadatrabalho ( id , descricao , trabalha_sabado) VALUES
  389.  
  390. ('0001' , 'segunda a domingo' , true),
  391. ('0002' , NULL , false),
  392. ('0003' , 'trabalha feriados' , true),
  393. ('0004' , ' ' , true ),
  394. ('0005' , ' ' , false),
  395. ('0006' , ' ', false),
  396. ('0007' , 'trabalha feriados' , true),
  397. ('0008' , ' ' , true),
  398. ('0009' , ' ' , true),
  399. ('0010' , ' ', true ),
  400. ('0011' , ' ', true),
  401. ('0012', ' ', true),
  402. ('0013' , ' ' , true),
  403. ('0014', ' ' , true),
  404. ('0015' , ' ', true ),
  405. ('0016'  , ' ' , false);
  406.  
  407.  
  408.  
  409.  
  410. -- TABELA DE TURNO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  411.  
  412. CREATE TABLE turno (
  413.  
  414.     cod char(4),
  415.     descricao varchar(60),
  416.     hora_inicio time not null,
  417.     hora_fim time not null,
  418.     primary key (cod)
  419.  
  420. );
  421.  
  422. -- inserindo valores na tabela de turno  OK
  423.  
  424. INSERT INTO turno ( cod, descricao , hora_inicio, hora_fim ) VALUES
  425.  
  426. ('0001' , ' ' , '07:30:00' , '16:30:00'),
  427. ('0002' , ' ', '08:40:00' , '17:40:00'),
  428. ('0003' , ' ' , '07:00:00' , '14:00:00'),
  429. ('0004' , ' ' , '11:00:00' , '17:00:00'),
  430. ('0005' , ' ' , '14:00:00' , '18:30:00'),
  431. ('0006' , ' ' , '13:35:00' , '19:45:00'),
  432. ('0007' , ' ' , '07:30:00' , '12:30:00'),
  433. ('0008' , ' ' , '07:10:00' , '13:30:00'),
  434. ('0009' , ' ' , '18:00:00' , '23:55:00'),
  435. ('0010' , ' ' , '00:00:01' , '08:00:01');
  436.  
  437.  
  438. -- TABELA DE DIA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  439.  
  440. CREATE TABLE dia (
  441.     sequencial char(4),
  442.     descricao varchar(60),
  443.     primary key (sequencial)
  444.    
  445. );
  446.  
  447. -- inserindo valores na tabela de dia OK
  448.  
  449. INSERT INTO dia ( sequencial , descricao ) VALUES
  450.  
  451. ('0001' , ' segunda-feira' ),
  452. ('0002' , ' terça-feira' ),
  453. ('0003' , ' quarta-feira' ),
  454. ('0004' , ' quinta-feira' ),
  455. ('0005' , ' sexta-feira' ),
  456. ('0006' , ' sabado' ),
  457. ('0007' , ' domingo' );
  458.  
  459.  
  460. -- TABELA DE ENTREGA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  461.  
  462. CREATE TABLE entrega (
  463.    
  464.     seq char(4) ,
  465.     CPF_entregador char(11) not null,
  466.     data_entrega date,
  467.     hora_estimada time,
  468.     primary key (seq),
  469.     foreign key(CPF_entregador) references entregador(CPF)
  470.  
  471. );
  472.  
  473.  -- inserindo valores na tabela de entrega OK
  474.  
  475. INSERT INTO entrega ( seq , CPF_entregador , data_entrega , hora_estimada ) VALUES
  476.  
  477. ('0001' , '33666472214' , '2016-04-09 ' , '07:30:00'),
  478. ('0002' , '33666472214' , '2016-04-09 ' , '19:45:00'),
  479. ('0003' , '33666472214' , '2016-04-09 ' , '18:00:00'),
  480. ('0004' , '33666472214' , '2016-04-09 ' , '09:30:00'),
  481. ('0005' , '33666472214' , '2016-04-09 ' , '13:30:00'),
  482. ('0006' , '86147207504' , '2016-04-02 ' , '06:30:00'),
  483. ('0007' , '86147207504' , '2016-04-02 ' , '11:45:00'),
  484. ('0008' , '86147207504' , '2016-04-02 ' , '14:00:00'),
  485. ('0009' , '86147207504' , '2016-04-02 ' , '015:30:00'),
  486. ('0010' , '86147207504' , '2016-04-02 ' , '14:30:00');
  487.  
  488.  
  489. -- TABELA DE COMPRA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  490.  
  491. CREATE TABLE compra (
  492.  
  493.     cod char(4),
  494.     seq_entrega char(4) not null,
  495.     valor_total float not null CHECK( valor_total > 0 ),
  496.     dia date not null,
  497.     valor_total_desconto float CHECK (valor_total_desconto >= 0 ),
  498.     statos boolean default true,
  499.     primary key (cod),
  500.     foreign key (seq_entrega) references entrega ( seq )
  501. );
  502.  
  503. -- inserindo valores na tabela de compra OK
  504.  
  505. INSERT INTO compra ( cod , seq_entrega , valor_total , dia , valor_total_desconto , statos ) VALUES
  506.  
  507. ('0001' , '0001 ' , 693 , '2016-04-09 ' , 0 , true ),
  508. ('0002' , '0002 ' , 789 , '2016-04-09 ' , 23.4 , true ),
  509. ('0003' , '0003 ' , 403 , '2016-04-09 ' , 4.2 , true ),
  510. ('0004' , '0004 ' , 233 , '2016-04-09 ' , 0 , true ),
  511. ('0005' , '0005 ' , 70  , '2016-04-09 ' , 0 , true ),
  512. ('0006' , '0006 ' , 2020 , '2016-04-02  ' , 20.2 , true ),
  513. ('0007' , '0007 ' , 400 , '2016-04-02  ' , 0 , true ),
  514. ('0008' , '0008 ' , 121 , '2016-04-02 ' , 0 , true ),
  515. ('0009' , '0009 ' , 133 , '2016-04-02 ' , 3.2 , true ),
  516. ('0010' , '0010 ' , 154 , '2016-04-02 ' , 0 , true );
  517.  
  518. -- TABELA DE COMPRA COMUM xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  519.  
  520. CREATE TABLE compra_comum (
  521.  
  522.     seq char(4),
  523.     cod char(4),
  524.     primary key(seq),
  525.     CONSTRAINT fk_compracomum foreign key (cod) references compra (cod) ON DELETE CASCADE ON UPDATE CASCADE
  526. );
  527.  
  528.  
  529. -- inserindo valores na tabela de compra comum OK
  530.  
  531. INSERT INTO compra_comum (seq , cod ) VALUES
  532.  
  533. ('0001','0001'),
  534. ('0002' ,'0003'),
  535. ('0003', '0005'),
  536. ('0004' ,'0006'),
  537. ('0005' ,'0008');
  538.  
  539. -- TABELA DE COMPRA PROGRAMADA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  540.  
  541. CREATE TABLE compra_programada (
  542.     seq char(4),
  543.     cod char(4),
  544.     data_1 date not null,
  545.     data2 date not null,
  546.     esta_ativa boolean default true,
  547.     primary key (seq),
  548.     CONSTRAINT fk_compraprogramada foreign key (cod) references compra (cod) ON DELETE CASCADE ON UPDATE CASCADE
  549. );
  550.  
  551. -- inserindo valores na tabela de compra programada
  552.  
  553. INSERT INTO compra_programada ( seq ,cod , date_1 , date2 , esta_ativa ) VALUES
  554.  
  555. ('0001' ,'0002' , '2016-04-09' , '2017-04-09' , true ),
  556. ('0002' , '0004' , '2016-04-09' , '2017-01-09' , true ),
  557. ('0003' , '0007' , '2016-04-02' , '2016-11-02' , true ),
  558. ('0004' ,'0009' , '2016-04-02' , '2017-02-02' , true ),
  559. ('0005' , '0010' , '2016-04-02' , '2017-04-02' , true );
  560.    
  561. -- TABELA ITEM DE COMPRA createdyes 13
  562.  
  563. CREATE TABLE item_compra (
  564.  
  565.     seq char(4),
  566.     cod_compra char(4) not null,
  567.     cod_produto char(4) not null,
  568.     quantidade int CHECK (quantidade > 0) ,
  569.     valor_desconto float default 0 CHECK (valor_desconto >= 0),
  570.     valor_unitario float CHECK (valor_unitario > 0),
  571.     primary key (seq),
  572.     foreign key (cod_compra) references compra (cod)
  573. );
  574.  
  575.  -- ITEM COMPRA INCOMPLETO
  576. -- INSERT INTO item_compra ( seq , cod_compra , cod_produto , quantidade , valor_desconto , valor_unitario ) VALUES
  577.  
  578.  
  579. -- TABELA DA MATRIZ xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  580.  
  581.  CREATE TABLE matriz (
  582.    
  583.     CNPJ char(14),
  584.     nomefantasia varchar(10) not null,
  585.     primary key (CNPJ)
  586.  
  587. );
  588. -- inserindo valores na tabela Matriz OK
  589. INSERT INTO matriz( CNPJ , nomefantasia ) VALUES
  590.  
  591. ( '23416393000114' , 'SUPER'),
  592. ( '23416393000140' , 'ICBPE'),
  593. ( '23416393000169' , 'ICBRJ'),
  594. ( '76166587000175' , 'FRUFRU'),
  595. ( '33353657000191' , 'BILU'),
  596. ( '01545535000100' , 'MILU' );
  597. SELECT *
  598. FROM matriz;
  599.  
  600. -- TABELA DE TELEFONE DA MATRIZ xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  601.  
  602. CREATE TABLE telefone_matriz (
  603.  
  604.     seq char(4),
  605.     CNPJ char(14),
  606.     telefone char(10),
  607.     primary key (seq),
  608.     CONSTRAINT fk_cnpjmatriz foreign key (CNPJ) references matriz (CNPJ) ON DELETE CASCADE ON UPDATE CASCADE
  609.  
  610. );
  611.  
  612. -- inserindo valores na tabela telefone_matriz OK
  613.  
  614. INSERT INTO telefone_matriz (seq , CNPJ , telefone ) VALUES
  615.  
  616. ('0001' , '23416393000114' , '8133002432'),
  617. ('0002 ',  '23416393000140' , '8133002149'),
  618. ('0003' , '23416393000140' , '1133002932'),
  619. ('0004' , '23416393000140' , '1140443949'),
  620. ('0005' , '23416393000169' , '1433004732'),
  621. ( '0006' ,'23416393000169' , '1440002449');
  622.  
  623.  
  624. -- TABELA DE FILIAL xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  625.  
  626. CREATE TABLE filial (
  627.  
  628.     seq char(4),
  629.     CNPJ_Matriz char(14),
  630.     CPF_gerente char(11) ,
  631.     endereco varchar(50),
  632.     qtd_func int(4) CHECK (qtd_func >= 0),
  633.     primary key ( seq ),
  634.     CONSTRAINT fk_cnpjmatrizfilial foreign key ( CNPJ_MATRIZ ) references matriz (CNPJ) ON DELETE CASCADE ON UPDATE CASCADE
  635.    
  636.  
  637. );
  638.  
  639. ALTER TABLE filial add constraint foreign key ( CPF_gerente ) references gerente (CPF); -- createdyes 13
  640.  
  641. -- inserindo valores na tabela filial OK
  642.  
  643. INSERT INTO filial ( seq , CNPJ_Matriz , CPF_gerente , endereco , qtd_func ) VALUES
  644.  
  645. ( '0001' ,  '23416393000114' , NULL , 'Rua valtavares ' , 4 ),
  646. ( '0002' ,  '23416393000114' , NULL , 'Rua alivetania ' , 4 ),
  647. ( '0003' ,  '23416393000140' , NULL, 'Rua maranguape ' , 4 ),
  648. ( '0004' ,  '23416393000169' , NULL , 'Rua fernigan ' , 4 );
  649.  
  650.  
  651. -- TABELA DE TELEFONE DA FILIAL xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  652.  
  653. CREATE TABLE telefone_filial (
  654.  
  655.     seq_filial char(4),
  656.     CNPJ_Matriz char(14),
  657.     telefone char(10),
  658.     primary key (seq_filial),
  659.     CONSTRAINT fk_seq foreign key (CNPJ_Matriz) references filial (CNPJ_Matriz) ON DELETE CASCADE ON UPDATE CASCADE
  660.  
  661. );
  662.  
  663. -- inserindo valores na tabela telefone_filial OK
  664.  
  665. INSERT INTO telefone_filial( seq_filial , CNPJ_Matriz , telefone ) VALUES
  666.  
  667. ( '0001' ,  '23416393000114' , '1133115021' ),
  668. ( '0002' ,  '23416393000114' , '1133505231' ),
  669. ( '0003' ,  '23416393000140' , '8143022151' ),
  670. ( '0004' ,  '23416393000169' , '1431205412' );
  671.  
  672.  
  673. -- TABELA DE PERDA DE PRODUTO createdyes 13
  674.  
  675. CREATE TABLE perda (
  676.  
  677.     seq char(4),
  678.     cod_lote char(4),
  679.     cod_produto char(4),
  680.     id_estoque char(4),
  681.     cpf_gerente char(11) not null,
  682.     dia date not null ,
  683.     quantidade_perdida int CHECK (quantidade_perdida > 0) ,
  684.     motivo varchar(80),
  685.     primary key (seq),
  686.     key(cod_lote , cod_produto , id_estoque),
  687.     foreign key (cpf_gerente) references gerente (cpf),
  688.     CONSTRAINT fk_perdaitestoq foreign key ( id_estoque ) references item_estoque(id_estoque ) ON DELETE CASCADE ON UPDATE CASCADE,
  689.     CONSTRAINT fk_perdalote foreign key (cod_lote) references item_estoque (cod_lote) ON DELETE CASCADE ON UPDATE CASCADE,
  690.     CONSTRAINT fk_perdaprod foreign key (cod_produto) references item_estoque (cod_produto)  ON DELETE CASCADE ON UPDATE CASCADE
  691. );
  692.  
  693. -- INSERT INTO perda ( seq , cod_lote, cod_produto, id_estoque, cpf_gerente , dia , quantidade_perdida , motivo)
  694.  
  695.  
  696. -- TABELA DE VEICULO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  697.  
  698. CREATE TABLE veiculo (
  699.  
  700.     placa char(7),
  701.     seq_filial char(4) not null,
  702.     CNPJ_matriz char(14) not null,
  703.     cod_garagem char(4) not null,
  704.     modelo varchar(15),
  705.     descricao varchar(15),
  706.     cor varchar(10),
  707.     ano year,
  708.     statuss boolean default true,
  709.     primary key (placa),
  710.     foreign key(seq_filial ) references filial(seq) ,
  711.     foreign key (CNPJ_matriz) references filial(CNPJ_Matriz),
  712.     foreign key(cod_garagem) references garagem (cod)
  713. );
  714.  
  715. -- inserindo valores na tabela veiculo OK
  716.  
  717. INSERT INTO veiculo ( placa , seq_filial , CNPJ_matriz , cod_garagem , modelo , descricao , cor , ano , statuss ) VALUES
  718.  
  719. ( 'PEX0220 ' ,  '0001' ,  '23416393000114' , '0001' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  720. ( 'PEX2030 ' ,  '0001' ,  '23416393000114' , '0001' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  721. ( 'VET4320 ' ,  '0002' ,  '23416393000114' , '0002' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  722. ( 'VET3240 ' ,  '0002' ,  '23416393000114' , '0002' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  723. ( 'WCV0943'  ,  '0003' ,  '23416393000114' , '0003' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  724. ( 'WCV3344 ' ,  '0003' ,  '23416393000114' , '0003' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  725. ( 'HLT0032 ' ,  '0004' ,  '23416393000114' , '0004' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  726. ( 'HLT3994 ' ,  '0004' ,  '23416393000114' , '0004' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true);
  727.  
  728.  
  729. -- TABELA DE GARAGEM xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  730.  
  731. CREATE TABLE garagem (
  732.  
  733.     cod char(4),
  734.     seq_filial char(4) not null ,
  735.     CNPJ_matriz char(14) not null,
  736.     descricao varchar(15),
  737.     capacidade int(3) not null,
  738.     num_veiculos_atual int(3),
  739.     primary key(cod),
  740.     foreign key(seq_filial ) references filial (seq),
  741.     foreign key (CNPJ_matriz) references filial(CNPJ_matriz)
  742.    
  743.  
  744. );
  745.  
  746. -- inserindo valores na tabela garagem OK
  747.  
  748. INSERT INTO garagem ( cod , seq_filial , CNPJ_matriz , descricao , capacidade , num_veiculos_atual ) VALUES
  749. ( '0001' , '0001' ,  '23416393000114' , null , 4 , 2 ),
  750. ( '0002' , '0002' ,  '23416393000114' , null , 4 , 2 ),
  751. ( '0003' , '0003' ,  '23416393000140' , null , 4 , 2 ),
  752. ( '0004' , '0004' ,  '23416393000169' , null , 4 , 2 );
  753.  
  754. SELECT *
  755. FROM garagem;
  756.    
  757. -- TABELA DE ESTOQUE xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx  createdyes 13
  758.  
  759. CREATE TABLE estoque (
  760.  
  761.     id char(4),
  762.     seq_filial char(7) not null,
  763.     cnpj_matriz char(14) not null,
  764.     descricao varchar(80),
  765.     dt_ultima_entrada date,
  766.     primary key (id),
  767.     foreign key (seq_filial) references filial (seq),
  768.     foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  769.    
  770. );
  771.  
  772.  
  773. -- inserindo valores na tabela estoque OK
  774.  
  775. INSERT INTO estoque ( id , seq_filial , cnpj_matriz , descricao , dt_ultima_entrada ) VALUES
  776.  
  777. ( '0001' , '0001' ,  '23416393000114' , null , '2018-01-04'),
  778. ( '0002' , '0002' ,  '23416393000114' , null , '2018-01-04'),
  779. ( '0003' , '0003' ,  '23416393000140' , null , '2018-01-04'),
  780. ( '0004' , '0004' ,  '23416393000169' , null , '2018-01-04');
  781.  
  782.  
  783. -- TABELA DE LOTE createdyes 13
  784.  
  785. CREATE TABLE lote (
  786.    
  787.     cod char(4),
  788.     cod_pedido_fornecedor char(4) not null,
  789.     descricao varchar(30),
  790.     data_chegada date not null,
  791.     primary key( cod) ,
  792.     foreign key (cod_pedido_fornecedor) references pedido_fornecedor (cod)
  793.  
  794. );
  795.  
  796. -- INSERT INTO lote ( cod, cod_pedido_fornecedor, descricao , data_chegada)
  797.  
  798.        
  799.  
  800. -- TABELA DE ITEM DE ESTOQUE createdyes 13
  801.  
  802. CREATE TABLE item_estoque (
  803.    
  804.     seq char(4),
  805.     cod_lote char(4),
  806.     id_estoque char(4),
  807.     cod_produto char(4),
  808.     id_avaria char(4) not null,
  809.     id_prateleira char(4) not null,
  810.     data_validade date not null,
  811.     data_fabricacao date not null,
  812.     data_entrada date not null,
  813.     valor_compra float CHECK (valor_compra > 0),
  814.     quantidade int CHECK (quantidade > 0),
  815.     primary key (seq),
  816.     foreign key (cod_lote) references lote (cod),
  817.     foreign key (id_estoque) references estoque (id),
  818.     CONSTRAINT fk_produtoestoque foreign key ( cod_produto ) references produto_ref( cod) ON DELETE CASCADE ON UPDATE CASCADE,
  819.     foreign key (id_avaria ) references avaria ( id),
  820.     foreign key (id_prateleira ) references prateleira ( codigo)
  821.    
  822. );
  823. -- INSERT INTO item_estoque (cod_lote, id_estoque , cod_produto , id_avaria , id_prateleira , data_validade ,
  824. /* data_fabricacao , data_entrada , valor_compra, quantidade)  
  825. */
  826.  
  827.  
  828.    
  829. -- TABELA MAQUINA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  830.  
  831. CREATE TABLE maquina (
  832.  
  833.     id char(4),
  834.     id_estoque char(4) not null,
  835.     id_operador char(11) not null,
  836.     ano year ,
  837.     combustivel varchar(30),
  838.     modelo varchar(30),
  839.     capacidade float , -- CAPACIDADE EM KG
  840.     elevavao_max float , -- ELEVAVAO EM METROS
  841.     garantia date,
  842.     tipo varchar(30),
  843.     comprimento float , -- COMPRIMENTO EM METROS
  844.     primary key (id),
  845.     foreign key (id_estoque) references estoque (id),
  846.     foreign key (id_operador) references estoquista (cpf)
  847. );
  848.  
  849. -- inserindo valores na tabela maquina OK
  850.  
  851. INSERT INTO maquina ( id , id_estoque , id_operador , ano, combustivel , modelo , capacidade , elevavao_max ,
  852. garantia , tipo , comprimento ) VALUES
  853.  
  854. ( '0001' , '0001' , '77491222226' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  855. ( '0002' , '0002' , '57859332507' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  856. ( '0003' , '0003' , '16565525749' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  857. ( '0004' , '0004' , '98243208909' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 );
  858.  
  859.  
  860. -- TABELA DE AVARIA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  861.  
  862. CREATE TABLE avaria (
  863.    
  864.     id char(4),
  865.     causa varchar(20) not null,
  866.     preco float(3) CHECK ( preco > 0 ),
  867.     obs varchar(40),
  868.     primary key(id)
  869.    
  870. );
  871.  
  872. -- inserindo valores na tabela avaria OK
  873.  
  874. INSERT INTO avaria (id , causa , preco , obs ) VALUES
  875.  
  876. ('0001' , 'Queda' , 30 , null ),
  877. ('0002' , 'Queda' , 10 , null ),
  878. ('0003' , 'Queda' , 200 , null ),
  879. ('0004' , 'Queda' , 32.2 , null ),
  880. ('0005' , 'Queda' , 230 , null ),
  881. ('0006' , 'Queda' , 92.2 , null );
  882.  
  883. -- TABELA DE PRATELEIRA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  884.  
  885. CREATE TABLE prateleira (
  886.  
  887.     codigo char(4),
  888.     altura float(2) not null,
  889.     comprimento float(2) not null,
  890.     posicao_nivel char(2),
  891.     primary key(codigo)
  892.  
  893. );
  894.  
  895. -- inserindo valores na tabela prateleira  OK
  896.  
  897. INSERT INTO prateleira ( codigo , altura , comprimento , posicao_nivel ) VALUES
  898.  
  899. ('0001' , 5 , 10 , 'A1' ),
  900. ('0002' , 5 , 10 , 'A2' ),
  901. ('0003' , 5 , 10 , 'A3' ),
  902. ('0004' , 5 , 10 , 'A4' ),
  903. ('0005' , 5 , 10 , 'A5' ),
  904. ('0006' , 5 , 10 , 'B1' ),
  905. ('0007' , 5 , 10 , 'B2' ),
  906. ('0008' , 5 , 10 , 'B3' ),
  907. ('0009' , 5 , 10 , 'B4' ),
  908. ('0010' , 5 , 10 , 'B5' ),
  909. ('0011' , 5 , 10 , 'C1' ),
  910. ('0012' , 5 , 10 , 'C2' ),
  911. ('0013' , 5 , 10 , 'C3' ),
  912. ('0014' , 5 , 10 , 'C4' ),
  913. ('0015' , 5 , 10 , 'C5' );
  914.  
  915. -- TABELA DE NCM DE PRODUTO createdyes 13
  916.  
  917. CREATE TABLE NCM (
  918.    
  919.     id char(4),
  920.     descricao varchar(40),
  921.     cod_mercosul char(9) not null,
  922.     primary key(id)
  923.  
  924. );
  925.  
  926. -- inserindo valores na tabela NCM OK
  927.  
  928. INSERT INTO NCM ( id , descricao , cod_mercosul) VALUES
  929.  
  930. ('0001', ' ' , '000000001'),
  931. ('0002' , ' ' , '000000002'),
  932. ('0003' , ' ', '000000003'),
  933. ('0004' , ' ', '000000004'),
  934. ('0005', ' ' , '000000005');
  935.  
  936. -- TABELA DE UNIDADE DE PRODUTO  createdyes 13
  937.  
  938. CREATE TABLE unidade (
  939.  
  940.     cod char(4),
  941.     descricao varchar(30),
  942.     sigla char(2) not null,
  943.     primary key(cod)
  944.    
  945.    
  946. );
  947.  
  948. -- inserindo valores na tabela unidade  OK
  949.  
  950. INSERT INTO unidade (cod, descricao , sigla) VALUES
  951.  
  952. ('0001', 'quilogramas', 'kg'),
  953. ('0002' , 'mililitros', 'mL'),
  954. ('0003', 'gramas' , 'g'),
  955. ('0004', 'litros' , 'L'),
  956. ('0005', 'miligramas' , 'mg');
  957.  
  958.  
  959. -- TABELA DE CATEGORIA DE PRODUTO createdyes 13
  960.  
  961. CREATE TABLE categoria (
  962.    
  963.     cod char(4),
  964.     descricao varchar(30) not null,
  965.     primary key (cod)
  966.  
  967. );
  968.  
  969. -- inserindo valores na tabela categoria OK
  970.  
  971. INSERT INTO categoria ( cod , descricao ) VALUES
  972.  
  973. ('0001', 'Condimentos' ),
  974. ('0002' , 'Laticinios'),
  975. ('0003', 'HortiFruti'),
  976. ('0004' , 'Conservas'),
  977. ('0005', 'Limpeza'),
  978. ('0006' , 'Bebidas Alcoolicas'),
  979. ('0007' , 'Bebidas nao Alcoolicas'),
  980. ('0008' , 'Graos e Cereais');
  981.  
  982. -- TABELA DE SUBCATEGORIA DE PRODUTO createdyes 13
  983.  
  984. CREATE TABLE subcategoria (
  985.  
  986.     cod char(4),
  987.     cod_categoria char(4) not null,
  988.     descricao varchar(30) not null,
  989.     primary key(cod),
  990.     foreign key (cod_categoria) references categoria(cod)
  991.  
  992. );
  993.  
  994. -- inserindo valores na tabela subcategoria OK
  995.  
  996. INSERT INTO subcategoria ( cod , cod_categoria , descricao ) VALUES
  997.  
  998. ('0001' , '0001' , 'Vinagres'),
  999. ('0002' , '0001' , 'Temperos'),
  1000. ('0003' , '0001' , 'Sal' ),
  1001. ('0004' , '0001', 'Azeites'),
  1002. ('0005' , '0001', 'Oleos'),
  1003. ('0006' , '0001', 'Especiarias'),
  1004. ('0007' , '0002', 'Leites'),
  1005. ('0008' , '0002', 'Iogurtes'),
  1006. ('0009' , '0002', 'Fermentados'),
  1007. ('0010' , '0002', 'Queijos'),
  1008. ('0011' , '0003', 'Ovos'),
  1009. ('0012' , '0003', 'Frutas secas'),
  1010. ('0013' , '0003', 'Legumes'),
  1011. ('0014' , '0004' , 'Frutas'),
  1012. ('0015' , '0004', 'Peixes'),
  1013. ('0016' , '0004', 'Vegetais'),
  1014. ('0017' , '0004', 'Cogumelos'),
  1015. ('0018' , '0005', 'Detergente'),
  1016. ('0019' , '0005', 'Desinfetante'),
  1017. ('0020' , '0005', 'Sabao em po'),
  1018. ('0021' , '0005', 'Sabao em barra'),
  1019. ('0022' , '0005', 'Amaciante');
  1020.  
  1021.  
  1022. -- TABELA DE MARCA DE PRODUTO createdyes 13
  1023.  
  1024. CREATE TABLE marca (
  1025.  
  1026.     cod char(4),
  1027.     descricao varchar(40),
  1028.     primary key(cod)
  1029.  
  1030. );
  1031.  
  1032. -- inserindo valores na tabela marca  OK
  1033.  
  1034. INSERT INTO marca ( cod , descricao ) VALUES
  1035.  
  1036. ('0001', 'Sadia'),
  1037. ('0002' , 'Knorr'),
  1038. ('0004' , 'Camponesa'),
  1039. ('0005' , 'Kicaldo'),
  1040. ('0006' , 'Vitarela'),
  1041. ('0007' , 'Bauduco'),
  1042. ('0008', 'OMO'),
  1043. ('0009' , 'Dona Benta'),
  1044. ('0010', 'Nestle');
  1045.  
  1046.  
  1047. -- TABELA DE FORNECEDOR xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1048.  
  1049. CREATE TABLE fornecedor (
  1050.  
  1051.     cod char(4),
  1052.     nome varchar(20) not null,
  1053.     CNPJ char(14) not null,
  1054.     rua varchar(20),
  1055.     bairro varchar(15),
  1056.     CEP char(8),
  1057.     estado varchar(15) not null,
  1058.     ativo boolean default true,
  1059.     primary key(cod)
  1060. );
  1061.  
  1062. -- inserindo valores na tabela fornecedor OK
  1063.  
  1064. INSERT INTO fornecedor ( cod , nome , CNPJ , rua , bairro , CEP , estado , ativo ) VALUES
  1065.  
  1066. ('0001' , 'Sadia'     , '55274471000180' , 'Rua valadares' , 'ipsep', '54330315' , 'Pernambuco' , true ) ,
  1067. ('0002' , 'Pampers'   , '26724671000180' , 'Rua cartomante' , 'ibura', '54202010' , 'Pernambuco' , true ) ,
  1068. ('0003' , 'Vitarela'  , '21712241000162' , 'Rua maniac' , 'algodão', '54215322' , 'São paulo' , true ) ,
  1069. ('0004' , 'Coca-cola' , '26804531000180' , 'Rua argola' , 'vale tinhaem ', '51215020' , 'Rio de janeiro' , true ) ,
  1070. ('0005' , 'Helmans'   , '77411981000180' , 'Rua sartre' , 'gitacity ', '44650201' , 'São paulo' , true ),
  1071. ('0006' , 'Bombril'   , '53686527000188' , 'Rua 3' , 'Varzea' , '50980320' , 'Recife' , true );
  1072.  
  1073.  
  1074. -- TABELA DE TELEFONE DE FORNECEDOR xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1075.  
  1076. CREATE TABLE telefone_fornecedor(
  1077.    
  1078.     seq char(4) ,
  1079.     cod_fornecedor char(4),
  1080.     telefone char(11),
  1081.     primary key(seq),
  1082.     CONSTRAINT fk_forn foreign key(cod_fornecedor) references fornecedor (cod) ON DELETE CASCADE ON UPDATE CASCADE
  1083.  
  1084. );
  1085.  
  1086. -- inserindo valores na tabela telefone_fornecedor OK
  1087.  
  1088. INSERT INTO telefone_fornecedor ( seq , cod_fornecedor, telefone) VALUES
  1089.  
  1090. ('0001' ,'0001' , '8133115544'),
  1091. ('0002' ,'0002' ,  '8133468952'),
  1092. ('0003' ,'0003' , '1140025632'),
  1093. ('0004' ,'0004', '1432456895'),
  1094. ('0005' , '0005', '1121452062');
  1095.  
  1096. -- TABELA  DE PRODUTO REF createdyes 13
  1097.  
  1098. CREATE TABLE produto_ref (
  1099.  
  1100.     cod char(4),
  1101.     id_unidade char(4),
  1102.     id_marca char(4),
  1103.     id_ncm char(4),
  1104.     id_categoria char(4),
  1105.     id_subcategoria char(4),
  1106.     id_fornecedor char(4),
  1107.     qtd_estoque int ,
  1108.     ICMS float,
  1109.     CST char(3),
  1110.     preco_por_tabela float,
  1111.     cod_barra char(13),
  1112.     freq_pedido float,
  1113.     descricao varchar(30),
  1114.     qtd_min int,
  1115.     qtd_total_estoque int,
  1116.     preco_ult_compra float,
  1117.     primary key (cod),
  1118.     foreign key (id_unidade) references unidade (cod),
  1119.     foreign key (id_marca) references marca (cod),
  1120.     foreign key (id_ncm) references ncm (id),
  1121.     foreign key (id_categoria) references categoria (cod),
  1122.     foreign key (id_subcategoria) references subcategoria (cod),
  1123.     foreign key (id_fornecedor) references fornecedor (cod)
  1124.  
  1125. );
  1126.  
  1127. -- INSERT INTO profuto_ref (cod, id_unidade , id_marca , id_ncm , id_categoria, id_subcategoria, id_fornecedor , qtd_estoque ,
  1128. /* ICMS , CST , preco_por_tabela , cod_barra , freq_pedido , descricao , qtd_min, qtd_total_estoque , preco_ult_compra)
  1129. */
  1130.  
  1131. -- TABELA DE INCIDENTE  xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1132.  
  1133. CREATE TABLE incidente (
  1134.  
  1135.     cod char(4),
  1136.     seq_entrega char(4) not null,
  1137.     dataa date not null,
  1138.     relatorio varchar(200),
  1139.     hora time not null,
  1140.     primary key(cod),
  1141.     foreign key ( seq_entrega) references entrega (seq)
  1142.  
  1143. );
  1144.  
  1145. -- inserindo valores na tabela incidente OK
  1146.  
  1147. INSERT INTO incidente (cod , seq_entrega , dataa, relatorio , hora ) VALUES
  1148.  
  1149. ('0001' , '0003' , '2016-04-09 ' , ' Tentativa de assalto ' , '18:06:00' ),
  1150. ('0002' , '0005' , '2016-04-09 ' , ' Tentativa de assalto ' , '13:34:00' ),
  1151. ('0003' , '0006' , '2016-04-02 ' , ' Tentativa de assalto ' , '06:32:00' );
  1152.  
  1153. -- TABELA DOCS xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1154.  
  1155. CREATE TABLE docs (
  1156.    
  1157.     seq char(4),
  1158.     cod_incidente char(4),
  1159.     docs varchar(20),
  1160.     primary key (seq),
  1161.     CONSTRAINT fk_incidente foreign key (cod_incidente) references incidente (cod ) ON DELETE CASCADE ON UPDATE CASCADE
  1162. );
  1163.  
  1164.  -- inserindo valores na tabela docs OK
  1165.  
  1166. INSERT INTO docs ( seq , cod_incidente , docs ) VALUES
  1167.  
  1168. ('0001' , '0001', null ) ,
  1169. ('0002' ,'0002' , null ) ,
  1170. ('0003' ,'0003' , null);
  1171.  
  1172. -- TABELA DE PAGAMENTO  createdyes 13
  1173.  
  1174. CREATE TABLE pagamento (
  1175.    
  1176.     cod char(4),
  1177.     id_fatura char(4) not null,
  1178.     cod_compra char(4) not null,
  1179.     cod_tipo_pagamento char(4) not null,
  1180.     valor_pago float CHECK ( valor_pago > 0 ),
  1181.     dia date not null,
  1182.     statos boolean default true ,
  1183.     tipo_pagamento enum ('Cartao credito', 'Cartao Debito', 'Boleto'),
  1184.     primary key (cod),
  1185.     foreign key (id_fatura) references fatura (id),
  1186.     foreign key (cod_compra) references compra (cod),
  1187.     foreign key (cod_tipo_pagamento) references tipo_pagamento ( cod)
  1188.    
  1189. );
  1190.  -- INSERT INTO pagamento ( cod, id_fatura ,cod_compra , cod_tipo_pagamento  , valor_pago , dia ,  statos, tipo_pagamento ) VALUES
  1191.  
  1192.  -- TABELA DE TIPO DE PAGAMENTO createdyes 13
  1193.  
  1194. CREATE TABLE tipo_pagamento (
  1195.    
  1196.     cod char(4),
  1197.     descricao varchar(30),
  1198.     primary key(cod)
  1199.  
  1200.  );
  1201.  
  1202.  -- inserindo valores na tabela tipo_pagamento  OK
  1203.  
  1204. INSERT INTO tipo_pagamento (cod, descricao ) VALUES
  1205. ('0001' , 'Boleto Bancario'),
  1206. ('0002' , 'Cartao de Credito'),
  1207. ('0003' , 'Cartao de Debito');
  1208.  
  1209.  
  1210.  
  1211. -- TABELA DE FATURA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1212.  
  1213. CREATE TABLE fatura (
  1214.  
  1215.     id char(4),
  1216.     cod_pedido_fornecedor char(4),
  1217.     data_vencimento date not null,
  1218.     valor_pago_atual float CHECK (valor_pago_atual > 0 ),
  1219.     valor_total_final float CHECK (valor_total_final > 0),
  1220.     data_emissao date not null,
  1221.     statos boolean default true,
  1222.     data_paga date,
  1223.     multa float,
  1224.     primary key (id),
  1225.     foreign key (cod_pedido_fornecedor) references pedido_fornecedor (cod)
  1226.  
  1227. );
  1228.    
  1229.    
  1230. -- TABELA DE NOTA FISCAL createdyes 13
  1231.  
  1232. CREATE TABLE nota_fiscal (
  1233.  
  1234.     NFE char(9),
  1235.     ICMS float not null,
  1236.     valor_total float not null CHECK ( valor_total > 0 ),
  1237.     valor_total_desconto float CHECK ( valor_total_desconto >= 0 ),
  1238.     dia date not null,
  1239.     valor_frete float,
  1240.     primary key (NFE)
  1241. );
  1242.  
  1243. --  inserindo valores na tabela nota_fiscal OK
  1244.  
  1245. INSERT INTO nota_fiscal (NFE , ICMS , valor_total, valor_total_desconto, dia , valor_frete) VALUES
  1246.  
  1247. ('111111109' ,  0.04 , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1248. ('111111104' ,  0.06 , 35.80 , 35.80, '2017-10-21' , 7.90),
  1249. ('111111113' ,  0.04 , 50.21 , 49.95 , '2012-03-27' , 10.32),
  1250. ('111111105' ,  0.06 , 173.98, 173.98 , '2010-06-13' , 8.50),
  1251. ('111111107' ,  0.02 , 50.43 , 50.43 , '2002-04-01' , 2.21),
  1252. ('111111108' ,  0.03 , 283.10 , 279.50 , '2011-11-11' , 4.30),
  1253. ('111111139' ,  0.02 , 123.54 , 111.20 , '2016-11-12' , 6.80),
  1254. ('111111199' ,  0.02 , 12.99 , 12.99 , '2016-11-13' , 8.30),
  1255. ('111111129' ,  0.03 , 346.10 , 336.10 , '2016-11-10' , 2.12);
  1256.    
  1257. -- TABELA DA NOTA FISCAL FORNECEDOR createdyes 13
  1258.  
  1259. CREATE TABLE nota_fiscal_fornecedor (
  1260.  
  1261.     NFE char(9),
  1262.     cod_pagamento char(4) not null,
  1263.     CFOP char(8) not null,
  1264.     IPI float,
  1265.     primary key(NFE),
  1266.     CONSTRAINT fk_ntfiscalfornecedor foreign key (NFE) references nota_fiscal (NFE) ON DELETE CASCADE ON UPDATE CASCADE,
  1267.     foreign key (cod_pagamento) references pagamento (cod)
  1268.  );
  1269.  
  1270.  -- NOTA FISCAL FORNEEDOR INCOMPLETO
  1271. INSERT INTO nota_fiscal_fornecedor (NFE, cod_pagamento , CFOP , IPI ) VALUES
  1272.  
  1273. ('111111109' ,  NULL , 143.98 , 120 , '2016-11-12' , 3.78),
  1274. ('111111104' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1275. ('111111105' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1276. ('111111145' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1277. ('111111184' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1278. ('111111110' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1279. ('111111133' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1280. ('111111199' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78);
  1281.  
  1282. -- TABELA NOTA FISCAL COMPRA createdyes 13
  1283.  
  1284. CREATE TABLE nota_fiscal_compra (
  1285.  
  1286.     NFE char(9),
  1287.     cod_pagamento char(4),
  1288.     primary key (NFE),
  1289.     CONSTRAINT fk_ntfiscalcompra foreign key (NFE) references nota_fiscal (NFE) ON DELETE CASCADE ON UPDATE CASCADE,
  1290.     foreign key (cod_pagamento) references pagamento (cod)
  1291.  
  1292. );
  1293.  
  1294. -- TABELA DE CLIENTE  createdyes 13
  1295.  
  1296. CREATE TABLE cliente (
  1297.  
  1298.     CPF char(11),
  1299.     seq_filial char(4) not null,
  1300.     cnpj_matriz char(14) not null,
  1301.     cep char(8) not null,
  1302.     cidade varchar(30),
  1303.     numero char(11),
  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,
  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) references filial (seq ),
  1317.     foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  1318.    
  1319. );
  1320.  
  1321.  
  1322. -- !!!!!!!!!!!!!!!!!!!!!! FALTA INCLUIR O CNPJ NAS TUPLAS !!!!!!!!!!!!!!!!
  1323.  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
  1324.  
  1325. ('54501233290' , '0001' , '23416393000114' , '52291045' , 'Recife' , '11111111111' ,  'Rua Jaguaribara' , 1200.00 , 'Melissa' , 'Andreia' , 'Nascimento', '1908234', false , '2016-02-12', '[email protected]' , '1999-06-13'),
  1326. ('25251145314' , '0002' , '23416393000114', '50999321' , 'Olinda' , null, 'Rua de Saão Bento' , 0 , 'Marcos' , 'Andre' , 'Marques' , '9123786' , 'xxx9' , false , '2015-03-11' , '[email protected]' , '1980-03-25' ),
  1327. ('13345509287' , '0001' , '23416393000114', '50348567' , 'Recife' , null , 'Rua Real da Torre ' , 0, 'Fatima' , 'Caixias' , 'Laffaiete' , '1866630' , '1233' , false , '2017-02-11' , '[email protected]' , '1972-09-09'),
  1328. ('77658476358' , '0001' , '23416393000114', '63900435' , 'Ceará' , null , 'Rua Chile' , 0 , 'Renato' , 'Murilo' , 'Dias' , '1266839' , '34g4' , false , '2017-07-04', '[email protected]' , '1989-12-29'),
  1329. ('50519774647' , '0002' , '23416393000114', '56332078' , 'Petrolina' ,  null, 'Rua Quarenta e Seis' , 22.30 , 'Joaquim', 'Luiz' , 'Campos' , '287101988' , '88uh' , true , '2016-04-04' , '[email protected]' , '1990-04-30'),
  1330. ('79317880797' , '0001' , '23416393000114', '82600130' , 'Curitiba' , null , 'Rua Bernardo Rosenmann' , 0, 'Alana' , 'Rodrigues', 'Mello',  '2368088' ,  '34f4' , true , '2016-09-11' , 'alana_[email protected]' , '1993-06-06'),
  1331. ('52125191105' , '0002' , '23416393000114', '77820026' , 'Araguaina' , null, 'Rua 16' , 0, 'Luana', 'Barbosa' , 'Pinto' , '1994566' , '9jf4' , true , '2016-09-11' , 'luaninha_[email protected]' , '1996-06-06'),
  1332. ('50130428361' , '0001' , '23416393000114', '77016638' , 'Palmas' , null , 'Quadra 509 Sul Alameda 7' , 0, 'Agatha', 'Vasconcelos' , 'Belarmino' , '4526174' , 'f56g' , true , '2016-03-04', 'agatinha_[email protected]' , '1999-09-09'),
  1333. ('96468793068' , '0001' , '23416393000114', '49069186' , 'Aracaju', null, 'Rua do Sol' , 0 , 'Camila' , 'Castro' , 'Raimundo' , '3199788' , 'kj004' , true , '2016-09-18', 'camila_[email protected]' , '1992-02-20'),
  1334. ('16512268903' , '0002', '23416393000114', '72876134' , 'Valparaíso de Goiás' , null, 'Quadra 37' , 23.33, 'Valkiria' , 'Queiroz' , 'Calado' , '4241822' , 'kd3io4' , true , '2016-02-12' , '[email protected]' , '1960-03-07'),
  1335. ('07617589689' , '0002' , '23416393000114', '89280577' , 'São Bento do Sul' , null, 'Rua Zanzibar' , 0, 'Angelica' , 'Meneses' , 'da Silva' , '4764955' , 'i4hfi4h' , false , '2017-02-05' , 'angelica_[email protected]' , '1992-12-11');
  1336.  
  1337.  
  1338. -- TABELA DE TELEFONE DE CLIENTE createdyes 13
  1339.  
  1340. CREATE TABLE telefone_cliente (
  1341.    
  1342.     CPF char(11) not null,
  1343.     telefone char(10),
  1344.     primary key (telefone),
  1345.     CONSTRAINT fk_telefonecliente foreign key (CPF) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1346. );
  1347.  
  1348.  INSERT INTO telefone_cliente ( CPF, telefone) VALUES
  1349.  
  1350.  ('54501233290' , '8134564432'),
  1351.  ('25251145314' , '8199890765'),
  1352.  ('77658476358' , '8599690359'),
  1353.  ('07617589689' , '4899097820'),
  1354.  ('07617589689' , '8191913012'),
  1355.  ('96468793068' , '7934876650'),
  1356.  ('96468793068' , '7988786534'),
  1357.  ('50519774647' , '8133234567');
  1358.  
  1359.  
  1360. -- TABELA DE SUGESTAO createdyes 13
  1361.  
  1362. CREATE TABLE sugestao (
  1363.    
  1364.     CPF_cliente char(11) not null,
  1365.     id char(4),
  1366.     dia date,
  1367.     descricao varchar(30) not null,
  1368.     primary key (id),
  1369.     CONSTRAINT fk_sugestao foreign key (CPF_cliente) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1370. );
  1371.  
  1372. INSERT INTO  sugestao (CPF_cliente, id, dia , descricao) VALUES
  1373.  
  1374. ('54501233290' , '0001' , '2016-02-12' , 'mais entregadores'),
  1375. ('54501233290' , '0002' , '2016-03-09' , 'mais entregadores'),
  1376. ('54501233290' , '0003' , '2016-03-09' , 'mais entregadores'),
  1377. ('54501233290' , '0004' , '2016-03-09' , 'mais entregadores'),
  1378. ('54501233290' , '0005' , '2016-03-09' , 'mais entregadores'),
  1379. ('54501233290' , '0006' , '2016-03-09' , 'mais entregadores'),
  1380. ('54501233290' , '0007' , '2016-03-09' , 'mais entregadores'),
  1381. ('54501233290' , '0008' , '2016-03-09' , 'mais entregadores'),
  1382. ('54501233290' , '0009' , '2016-03-09' , 'mais entregadores');
  1383.  
  1384.  
  1385. -- TABELA DE RECLAMACAO createdyes 13
  1386.  
  1387. CREATE TABLE reclamacao (
  1388.  
  1389.     CPF_cliente char(11) not null,
  1390.     id char(4),
  1391.     descricao varchar(30) not null,
  1392.     motivo varchar(20),
  1393.     data_ocorrido date not null,
  1394.     data_reclamacao date,
  1395.     primary key (id),
  1396.     CONSTRAINT fk_reclamacao foreign key (CPF_cliente) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1397. );
  1398.  
  1399. INSERT INTO reclamacao ( CPF_cliente , id , motivo, data_ocorrido, data_reclamacao) VALUES
  1400.  
  1401. ('54501233290' , '0001' , 'atendimento muito demorado', '2016-03-09' , '2016-03-13'),
  1402. ('54501233290' , '0002' , 'produto estava perto de vencer', '2016-03-09' , '2016-03-13'),
  1403. ('54501233290' , '0003' , 'o entregador nao chegou', '2016-03-01' , '2016-03-20'),
  1404. ('54501233290' , '0004' , 'erraram o endereco de entrega', '2016-03-09' , '2016-03-13'),
  1405. ('54501233290' , '0005' , 'atendimento muito demorado', '2016-03-09' , '2016-03-10'),
  1406. ('54501233290' , '0006' , 'site fora do ar', '2016-04-01' , '2016-04-01'),
  1407. ('54501233290' , '0007' , 'atendimento muito demorado', '2016-03-09' , '2016-03-13');
  1408.  
  1409.  
  1410. -- TABELA DE PROMOCAO createdyes 13
  1411.  
  1412. CREATE TABLE promocao (
  1413.  
  1414.     cod char(4),
  1415.     seq_filial char(4) not null,
  1416.     cnpj_matriz char(14) not null,
  1417.     nome varchar(30),
  1418.     data_inicio date not null,
  1419.     percentual_reducao float not null CHECK ( percentual_reducao > 0 ),
  1420.     data_fim date,
  1421.     obs varchar(30),
  1422.     descricao varchar(50),
  1423.     primary key (cod),
  1424.     foreign key (seq_filial ) references filial (seq),
  1425.     foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  1426.  
  1427. );
  1428.  
  1429. -- inserindo valores na tabela promocao OK
  1430.  
  1431. INSERT INTO promocao (cod, seq_filial , cnpj_matriz , nome , data_inicio, percentual_reducao , data_fim, obs, descricao) VALUES
  1432.  
  1433. ('0001' , '0001 ',  '23416393000114', 'Um barato no pedaco' , '2017-02-05', 0.13 , '2017-03-05' , 'n inclui importados' , 'promocao para laticinios'),
  1434. ('0002' , '0001' ,  '23416393000114', 'Queima de estoque' , '2016-12-22' , 0.33 , '2016-12-31' , NULL , NULL),
  1435. ('0003' , '0002',  '23416393000114','Mes da verdura' , '2017-08-12' , 0.26 , '2017-10-12' , 'n inclui conservas' , 'promocao para hortifruti' ),
  1436. ('0004' , '0002' ,  '23416393000114', 'Mes da conserva' , '2017-11-20' , 0.21 , '2017-12-20', NULL , 'apenas conservas' ),
  1437. ('0005 ', '0001' , '23416393000114', 'Desinfetantes em queima' , '2018-01-02' , 0.24 , '2018-02-02' , NULL , 'apenas desinfetantes'),
  1438. ('0006' , '0002' , '23416393000114', 'Promocao de amaciante' , '2017-09-15' , 0.12, '2017-11-15' , NULL , 'amaciantes nacionais'),
  1439. ('0007' , '0001' , '23416393000114', 'Laticinios vao a loucura' , '2018-01-02', 0.29, '2018-03-02' , NULL , 'reducao de preco laticinios'),
  1440. ('0008' , '0002' ,  '23416393000114','Promocao de Sabao em po' , '2017-06-15' , 0.19 , '2017-07-15' , NULL , 'promocao sabao em po');
  1441.  
  1442. -- TABELA DE PEDIDO FORNECEDOR createdyes 13
  1443.  
  1444. CREATE TABLE pedido_fornecedor (
  1445.    
  1446.     cod char(4),
  1447.     CPF_gerente char(11) not null,
  1448.     total_desconto float CHECK ( total_desconto >= 0 ),
  1449.     valor_total_IPI float CHECK ( valor_total_IPI >= 0 ),
  1450.     CFOP char(4) not null,
  1451.     valor_total float CHECK ( valor_total >= 0),
  1452.     dia date not null,
  1453.     statos boolean default true,
  1454.     valor_frete float CHECK (valor_frete >= 0),
  1455.     primary key (cod),
  1456.     foreign key (CPF_gerente) references gerente (CPF)
  1457. );
  1458.  
  1459. -- inserindo valores na tabela pedido_fornecedor OK
  1460.  
  1461.  INSERT INTO pedido_fornecedor ( cod, CPF_gerente , total_desconto , valor_total_IPI, CFOP, dia , statos, valor_frete ) VALUES
  1462.  
  1463. ('0001' , '96202875763' , 12380.00, 354.20 , '0001', '2017-12-09' , true , 12.90),
  1464. ('0002', '96202875763' , 3456.40 , 123.20 , '0002', '2017-11-09' , true , 10.30),
  1465. ('0003' , '96202875763' , 2280.25 , 220.00,'0003',  '2017-06-13', true , 28.50),
  1466. ('0004' , '96202875763' , 12200.00, 123.99,'0004',  '2017-07-04', true , 9.89),
  1467. ('0005' , '96202875763' , 990.00 , 19.89,  '0005',  '2016-12-09', true , 12.43),
  1468. ('0006' , '96202875763' , 5660.00, 56.70 , '0006', '2015-08-27' , true , 6.98),
  1469. ('0007' , '96202875763' , 2890.00 , 35.47 , '0007', '2016-04-12' , true , 10.20),
  1470. ('0008' , '96202875763' , 1873.20 , 190.00 ,'0008' , '2017-01-04' , true , 8.33),
  1471. ('0009' , '96202875763' , 2348.80, 111.10 , '0009' ,'2017-06-09' , true , 10.22),
  1472. ('0010' , '02123011878' , 1300.00, 132.30 , '0010','2017-08-27' , true , 11.30);
  1473.  
  1474. -- TABELA DE ITEM PEDIDO createdyes 13
  1475.  
  1476. CREATE TABLE item_pedido (
  1477.  
  1478.     seq char(4),
  1479.     cod_produto_ref char(4) not null,
  1480.     cod_pedido_fornecedor char(4) not null,
  1481.     quantidade int not null CHECK (quantidade > 0) ,
  1482.     preco_unitario float  not null CHECK (preco_unitario  > 0),
  1483.     primary key (seq),
  1484.     foreign key (cod_produto_ref) references produto_ref (cod),
  1485.     foreign key (cod_pedido_fornecedor) references pedido_fornecedor(cod)
  1486. );
  1487.  
  1488. -- INSERT INTO item_pedido (seq , cod_produto_ref , cod_pedido_fornecedor, quantidade , preco_unitario) VALUES
  1489.  
  1490.  
  1491. -- TABELA DE RELACIONAMENTO TEM DE FUNCIONARIO createdyes 13
  1492.  
  1493. CREATE TABLE tem (
  1494.      
  1495.     seq char(4),
  1496.     id_jornada char(4),
  1497.     id_turno char(4),
  1498.     id_dia char(4),
  1499.     primary key (seq),
  1500.     foreign key (id_jornada) references jornadatrabalho(id),
  1501.     foreign key (id_turno) references turno(cod),
  1502.     foreign key (id_dia) references dia (sequencial)
  1503.    
  1504. );
  1505.    
  1506.  
  1507. -- INSERT INTO tem (id_jornada , id_turno, id_dia ) VALUES
  1508.  
  1509.  
  1510.  
  1511. -- TABELA RELACIONAMENTO REALIZA CURSO createdyes 13
  1512.  
  1513. CREATE TABLE realizacurso (
  1514.    
  1515.     seq char(4),
  1516.     cpf_fun char(11),
  1517.     id_curso char(4),
  1518.     dt_inicio date,
  1519.     dt_fim date,
  1520.     primary key (seq),
  1521.     foreign key (cpf_fun) references funcionario(CPF),
  1522.     foreign key (id_curso) references curso (id)
  1523. );
  1524.  
  1525. INSERT INTO realizacurso ( seq , cpf_fun , id_curso , dt_inicio , dt_fim) VALUES
  1526.  
  1527. ('0001','77491222226', '2101' , '2016-02-13' , '2016-03-15' ),
  1528. ('0002', '77491222226' , '8012' , '2016-04-09' , '2016-06-09' ),
  1529. ('0003', '32568071001' , '2101' ,'2016-02-13' , '2016-03-15' ),
  1530. ('0004', '45321186898' , '8012' , '2016-04-09' , '2016-06-09' ),
  1531. ('0005', '77491222226' , '8012' , '2016-04-09' , '2016-06-09' ),
  1532. ('0006' ,'14073416260' , '8012' , '2016-04-09' , '2016-06-09' ),
  1533. ('0007', '88356795591' , '8012' , '2016-04-09' , '2016-06-09' );
  1534.  
  1535. -- TABELA DE GERENCIA DE ESTOQUE/* createdyes 13
  1536.  
  1537. CREATE TABLE gerencia_estoque (
  1538.    
  1539.     seq char(4),
  1540.     cpf_super_estoque char(11),
  1541.     id_estoque char(4),
  1542.     dt_fim date,
  1543.     dt_inicio date,
  1544.     primary key (seq),
  1545.     foreign key (cpf_super_estoque) references SupervisorEstoque (CPF),
  1546.     foreign key (id_estoque) references estoque(id)
  1547.    
  1548. );
  1549.  
  1550. SELECT *
  1551. FROM gerencia_estoque;
  1552.  
  1553.  INSERT INTO gerencia_estoque (seq, cpf_super_estoque, id_estoque , dt_fim, dt_inicio) VALUES
  1554.  
  1555. ('0001' ,'14073416260' , '0000001' ,'2017-03-02' ,'2016-03-02'),
  1556. ('0002', '85902755239' , '0000002' , '2017-04-15' , '2016-02-15'),
  1557. ('0003', '88356795591' , '0000003' , '2016-01-01' , '2014-02-13'),
  1558. ('0004', '14073416260' , '0000002 ' , '2013-06-22' , '2012-06-10'),
  1559. ('0005', '85902755239' , '0000003'  ,'2017-09-02', '2016-01-02' );
Advertisement
Add Comment
Please, Sign In to add comment