Advertisement
11eimilia11

Super almost done

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