Advertisement
11eimilia11

um dia isso vai ter fim

Jan 11th, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 55.35 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 1
  35. # --------------------------------ALTERANDO --------------------------------
  36.  
  37. CREATE TABLE funcionario (
  38.  
  39.     CPF char(11) ,
  40.     id_jornada char(4) , # NAO TEM RELACIONAMENTO OBRIG , TIREI O NOT NULL
  41.     seq_filial char(4),
  42.     cnpj_matriz char(14) not null,
  43.     data_admissao date,
  44.     sex enum ('M', 'F'),
  45.     estado_civil varchar(10),
  46.     login varchar(60) default 'func' ,
  47.     senha varchar(15) default 'func',
  48.     RG char(7) not null UNIQUE,
  49.     nome varchar(45),
  50.     situacao varchar(10)    ,
  51.     endereco varchar(45),
  52.     primary key(CPF),
  53.     foreign key (id_jornada) references jornadatrabalho (id) ,
  54.     foreign key ( seq_filial ) references filial (seq),
  55.     foreign key (cnpj_matriz) references matriz (CNPJ)
  56.  
  57. );
  58.  
  59.  
  60. -- inserindo valores para funcionario OK
  61.  
  62. INSERT INTO funcionario (CPF, id_jornada, seq_filial, cnpj_matriz, data_admissao, sex, estado_civil, login, senha, RG, nome, situacao, endereco) VALUES
  63.  
  64. ('77491222226' , '0001', '0001' ,  '23416393000114' , '2005-04-12' , 'F', 'solteiro' , 'helo.12' , '123' ,  '1259312' , 'Heloisa Macedo de Souza' , 'ativo' , 'Rua Eloy Monteiro Nunes'),
  65. ('98243208909' , '0002' , '0001' ,'23416393000114' , '2007-07-25' , 'M' , 'casado' , 'Garza2019' , 'E3221' ,'3654296' , 'Elias ChateauBriand Gomes' , 'inativo' , 'Avenida Paraíba'),
  66. ('57325297050' , '0003' , '0003' , '23416393000140', '2003-09-02', 'F', 'viuva' , 'Riggs642' , 'YM' ,       '4563573' , 'Maria Helena Rosendo' , 'ativo', 'Rua Pedro Viana Neto'),
  67. ('16565525749' , '0004' , '0002' , '23416393000114' , '2000-01-07', 'F', 'solteiro' , 'Eugene759' , 'XX133','2144770', 'Afrodite Bezerra das Flores' , 'ativo', 'Rua Amelia'),
  68. ('57859332507', '0005' , '0002' ,  '23416393000114' , '2006-02-02' , 'M' , 'solteiro' , 'TM1' , '98UJ' ,    '1555582' , 'Mauricio de Souza Carvalho' , 'ativo' , ' Rua da Concordia'),
  69. ('96202875763' , '0006' , '0003' , '23416393000140' , '2001-09-11' , 'F' , 'solteiro' ,'Juli.Alves', '8900','3494135' , 'Juliana Macedo Pinheiro' , 'inativo' , 'Rua Tucano'),
  70. ('02123011878' , '0007' , '0004' , '23416393000169' , '2000-08-10' , 'M' , 'solteiro' , 'ana.mari' , 'bb34','1783833' , 'Mariana Siqueira Jardim' , 'ativo' , 'Rua Lealberto Leal'),
  71. ('15141182894' , '0008' , '0001' , '23416393000114' , '2005-06-13' , 'F' , 'casado' , 'dudu.arda' , '1999' ,'2267700', 'Bernadete Maria da Silva' , 'ativo' , 'Rua Guajuvira'),
  72. ('33666472214' , '0009' , '0004' , '23416393000169' , '2011-03-01' , 'F' , 'solteiro', 'ana.belle' , 'AX6', '4137799','Anabelle Cristina Leal de Figueiredo' , 'ativo', 'Rua Manuel de Medeiros'),
  73. ('32568071001', '0010' , '0001' ,  '23416393000114' , '2010-09-26' , 'F' , 'casado' , 'bee.a' , '134N' ,    '4163131', 'Ana Beatriz Castanho Guedes' , 'ativo', 'Rua Jornalista Benedito Cunha'),
  74. ('45321186898' , '0011', '0004',   '23416393000169' , '2007-09-20', 'M' , 'solteiro' , 'alan.marq' , '0j7e','1557345','Allan Jose Malta de Souza' , 'inativo', ' Rua Projetada'),
  75. ('86147207504' , '0012' , '0004' , '23416393000169' , '2001-10-27' , 'F' , 'casado' , 'lelezinha' , '223d' ,'3217467', 'Leticia Santana Rodrigues' , 'ativo' , 'Rua Felipe Guerra'),
  76. ('85902755239' , '0013' , '0003' , '23416393000140' , '2005-11-14' , 'F' , 'solteiro' , 'mwd2', '1332',     '2437550', 'Gabriela Amado Batista', 'ativo', 'Rua da Palma'),
  77. ('14073416260' , '0014' , '0002' , '23416393000114', '2000-02-14', 'M' , 'casado', 'mumu321', '9901',       '1190089','Jadiane Matoso dos Santos', 'ativo', 'Rua Real da Torre'),
  78. ('32970753502', '0015' , '0002' ,  '23416393000114' , '2013-01-10', 'F' , 'solteiro' , 'JH10' , '1132' ,    '2422874', 'Viviane Mendonca do Nascimento', 'ativo', 'Rua da Harmonia'),
  79. ('88356795591' , '0016' , '0003' , '23416393000140' , '2012-06-10', 'M' , 'casado', '991jj', '1233',        '1316411', 'Ronaldo Fagundes da Silva' , 'ativo', 'Rua da Praia');
  80.  
  81. -- TABELA DE ESTOQUISTA HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  82. # ------------- ALTERANDO VALORES ------------------
  83.  
  84. CREATE TABLE estoquista (
  85.    
  86.     CPF char(11), -- REMOVI O SEQ E COLOQUEI O CPF COMO FK
  87.     CONSTRAINT estoquista_pk primary key (CPF),
  88.     CONSTRAINT fk_estoq foreign key (CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  89.  
  90. );
  91.  
  92.  -- inserindo valores para estoquista OK
  93.  
  94. INSERT INTO estoquista (CPF) VALUES
  95.  
  96. ('77491222226'),
  97. ('98243208909'),
  98. ('57859332507'),
  99. ('16565525749');
  100.  
  101. -- TABELA DE DBA HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  102. # ------------- ALTERANDO VALORES ------------------
  103. CREATE TABLE DBA (
  104.    
  105.     CPF char(11), # REMOVI O SEQ E COLOQUEI A PK COMO CPF
  106.     CONSTRAINT DBA_pk primary key (CPF),
  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 (CPF) VALUES
  113.  
  114. ('45321186898');
  115.  
  116. -- TABELA DE GERENTE HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  117.  # ------------- ALTERANDO VALORES ---------------
  118. CREATE TABLE gerente(
  119.    
  120.     CPF char(11), # TIREI O SEQ E COLOQUEI O CPF COMO PK
  121.     CONSTRAINT gerente_pk primary key (CPF),
  122.     CONSTRAINT fk_gerente foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  123.  
  124. );
  125.  
  126. -- inserindo valores para gerente OK
  127.  
  128. INSERT INTO gerente (CPF) VALUES
  129.  
  130. ('96202875763'),
  131. ('02123011878'),
  132. ('15141182894'),
  133. ('57325297050');
  134.  
  135. -- TABELA DE ENTREGADOR HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  136.  
  137. CREATE TABLE entregador(
  138.    
  139.     CPF char(11),
  140.     CONSTRAINT entregador_pk primary key (CPF),
  141.     CONSTRAINT fk_entregador foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  142.  
  143. );
  144.  
  145. -- inserindo valores na tabela entregador OK
  146.  
  147. INSERT INTO entregador (CPF) VALUES
  148.  
  149. ( '33666472214'),
  150. ('86147207504'),
  151. ('32970753502'),
  152. ('32568071001');
  153.  
  154. -- TABELA DE SUPERVISOR ESTOQUE HERDA FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  155. # --------------------ALTERANDO VALORES-----------------------
  156. CREATE TABLE supervisorestoque (
  157.    
  158.     CPF char(11), # REMOVI SEQ E COLOQUEI O CPF COMO PK
  159.     CONSTRAINT supervisorestoque_pk primary key(seq),
  160.     CONSTRAINT fk_super foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  161.  
  162. );
  163.  
  164. -- inserindo valotes na tabela supervisorestoque OK
  165.  
  166. INSERT INTO supervisorestoque (CPF) VALUES
  167.  
  168. ('14073416260'),
  169. ('85902755239' ),
  170. ('88356795591');
  171.  
  172.  
  173. -- TABELA MULTVALORADA DE FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  174.  #---------------------ALTERANDO VALORES ------------------
  175.  
  176. CREATE TABLE telefone_funcionario(
  177.    
  178.     CPF char(11), # REMOVI O SEQ E COLOQUEI A CHAVE COMPOSTA
  179.     telefone char(11),
  180.     CONSTRAINT telefone_funcionario_pk primary key (CPF, telefone),
  181.     CONSTRAINT fk_telefonefuncinario foreign key(CPF) references funcionario(CPF) ON DELETE CASCADE ON UPDATE CASCADE
  182.  
  183. );
  184.  
  185. -- inserindo valores na tabela de telefone_funcionario OK
  186.  
  187. INSERT INTO telefone_funcionario ( CPF, telefone ) VALUES
  188.  
  189. ('14073416260' , '08133552321'),
  190. ('85902755239' , '08132324567'),
  191. ('88356795591', '08131311111'),
  192. ('32568071001', '08134587831'),
  193. ('32970753502', '08132324502'),
  194. ('32970753502' , '08191912343'),
  195. ('33666472214' , '08199096532'),
  196. ('86147207504', '08132732100'),
  197. ('96202875763' , '08199690359');
  198.  
  199.  
  200. -- TABELA DE NOTIFICAÇÃO DADA A FUNCIONARIO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  201.  
  202. CREATE TABLE notificacao (
  203.    
  204.     id char(4),
  205.     cpf_fun char(11) not null,
  206.     dia date not null,
  207.     descricao varchar(80),
  208.     CONSTRAINT notificacaco_pk  primary key (id ),
  209.     foreign key (Cpf_fun) references funcionario (CPF)
  210.    
  211. );
  212.  
  213. -- inserindo valores na tabela de notificacao OK
  214.  
  215. INSERT INTO notificacao (id, cpf_fun, dia, descricao) VALUES
  216.  
  217. ('2940' , '33666472214' , '2014-02-26' , NULL), -- ENTREGADOR
  218. ('2941' , '86147207504' , '2015-03-06' , NULL), -- ENTREGADOR
  219. ('2942' , '32970753502' , '2015-06-02' , NULL), -- ENTREGADOR
  220. ('2943' , '33666472214' , '2014-07-20' , NULL),  
  221. ('2944' , '33666472214' , '2014-07-20' , NULL),
  222. ('2945' , '16565525749' , '2014-02-12' , NULL),
  223. ('2946' , '33666472214' , '2015-03-06' , NULL),
  224. ('2947' , '33666472214' , '2015-06-02' , NULL),
  225. ('2948' , '77491222226' , '2014-07-20' , NULL),
  226. ('2949' , '88356795591' , '2014-07-20' , NULL),
  227. ('2950' , '45321186898' , '2014-07-20' , NULL),
  228. ('2951' , '86147207504' , '2014-02-10' , NULL);
  229.  
  230. -- TABELA DE NOTIFICAÇÃO DE MULTA DADA A FUNCIONARIO HERDA DE NOTIFICAÇÃO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx
  231.  -- createdyes 13
  232.  # ---------------------ALTERANDO VALORES ---------------------
  233.  
  234. CREATE TABLE notif_multa (
  235.  
  236.     id char(4), # REMOVI SEQ E DEIXEI ID COMO PK
  237.     pontos_cnh int,
  238.     valor float not null,
  239.     cep char(8),
  240.     complemento varchar(30),
  241.     CONSTRAINT notif_multa_pk primary key(id),
  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 (id , pontos_cnh, valor, cep, complemento) VALUES
  249.  
  250. ('2940',  3 , 58.50 , 50789123 , 'Rua da Aurora'),
  251. ('2941' ,4 , 198.50 , 54330315 , 'Rua Itacuruba'),
  252. ('2942' , 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.     foreign key (cod_produto) references produto_ref (cod)
  574. );
  575.  
  576.  -- ITEM COMPRA INCOMPLETO
  577.  
  578.  #INSERT INTO item_compra ( seq , cod_compra , cod_produto , quantidade , valor_desconto , valor_unitario ) VALUES
  579. #('0001' , '0001' ,
  580.  
  581.  
  582. -- TABELA DA MATRIZ xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  583.  
  584.  CREATE TABLE matriz (
  585.    
  586.     CNPJ char(14),
  587.     nomefantasia varchar(10) not null,
  588.     primary key (CNPJ)
  589.  
  590. );
  591.  
  592. -- inserindo valores na tabela Matriz OK
  593.  
  594. INSERT INTO matriz( CNPJ , nomefantasia ) VALUES
  595.  
  596. ( '23416393000114' , 'SUPER'),
  597. ( '23416393000140' , 'ICBPE'),
  598. ( '23416393000169' , 'ICBRJ'),
  599. ( '76166587000175' , 'FRUFRU'),
  600. ( '33353657000191' , 'BILU'),
  601. ( '01545535000100' , 'MILU' );
  602.  
  603. -- TABELA DE TELEFONE DA MATRIZ xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  604.  
  605. CREATE TABLE telefone_matriz (
  606.  
  607.     seq char(4),
  608.     CNPJ char(14),
  609.     telefone char(10),
  610.     primary key (seq),
  611.     CONSTRAINT fk_cnpjmatriz foreign key (CNPJ) references matriz (CNPJ) ON DELETE CASCADE ON UPDATE CASCADE
  612.  
  613. );
  614.  
  615. -- inserindo valores na tabela telefone_matriz OK
  616.  
  617. INSERT INTO telefone_matriz (seq , CNPJ , telefone ) VALUES
  618.  
  619. ('0001' , '23416393000114' , '8133002432'),
  620. ('0002 ',  '23416393000140' , '8133002149'),
  621. ('0003' , '23416393000140' , '1133002932'),
  622. ('0004' , '23416393000140' , '1140443949'),
  623. ('0005' , '23416393000169' , '1433004732'),
  624. ( '0006' ,'23416393000169' , '1440002449');
  625.  
  626.  
  627. -- TABELA DE FILIAL xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  628.  
  629. CREATE TABLE filial (
  630.  
  631.     seq char(4),
  632.     CNPJ_Matriz char(14),
  633.     CPF_gerente char(11) ,
  634.     endereco varchar(50),
  635.     qtd_func int(4) CHECK (qtd_func >= 0),
  636.     primary key ( seq ),
  637.     CONSTRAINT fk_cnpjmatrizfilial foreign key ( CNPJ_MATRIZ ) references matriz (CNPJ) ON DELETE CASCADE ON UPDATE CASCADE
  638.    
  639.  
  640. );
  641.  
  642. ALTER TABLE filial add constraint foreign key ( CPF_gerente ) references gerente (CPF); -- createdyes 13
  643.  
  644. -- inserindo valores na tabela filial OK
  645.  
  646. INSERT INTO filial ( seq , CNPJ_Matriz , CPF_gerente , endereco , qtd_func ) VALUES
  647.  
  648. ( '0001' ,  '23416393000114' , NULL , 'Rua valtavares ' , 4 ),
  649. ( '0002' ,  '23416393000114' , NULL , 'Rua alivetania ' , 4 ),
  650. ( '0003' ,  '23416393000140' , NULL, 'Rua maranguape ' , 4 ),
  651. ( '0004' ,  '23416393000169' , NULL , 'Rua fernigan ' , 4 );
  652.  
  653.  
  654. -- TABELA DE TELEFONE DA FILIAL xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  655.  
  656. CREATE TABLE telefone_filial (
  657.  
  658.     seq_filial char(4),
  659.     CNPJ_Matriz char(14),
  660.     telefone char(10),
  661.     primary key (seq_filial),
  662.     CONSTRAINT fk_seq foreign key (CNPJ_Matriz) references filial (CNPJ_Matriz) ON DELETE CASCADE ON UPDATE CASCADE
  663.  
  664. );
  665.  
  666. -- inserindo valores na tabela telefone_filial OK
  667.  
  668. INSERT INTO telefone_filial( seq_filial , CNPJ_Matriz , telefone ) VALUES
  669.  
  670. ( '0001' ,  '23416393000114' , '1133115021' ),
  671. ( '0002' ,  '23416393000114' , '1133505231' ),
  672. ( '0003' ,  '23416393000140' , '8143022151' ),
  673. ( '0004' ,  '23416393000169' , '1431205412' );
  674.  
  675.  
  676. -- TABELA DE PERDA DE PRODUTO createdyes 13
  677.  
  678. CREATE TABLE perda (
  679.  
  680.     seq char(4),
  681.     cod_lote char(4),
  682.     cod_produto char(4),
  683.     id_estoque char(4),
  684.     cpf_gerente char(11) not null,
  685.     dia date not null ,
  686.     quantidade_perdida int CHECK (quantidade_perdida > 0) ,
  687.     motivo varchar(80),
  688.     primary key (seq),
  689.     key(cod_lote , cod_produto , id_estoque),
  690.     foreign key (cpf_gerente) references gerente (cpf),
  691.     CONSTRAINT fk_perdaitestoq foreign key ( id_estoque ) references item_estoque(id_estoque ) ON DELETE CASCADE ON UPDATE CASCADE,
  692.     CONSTRAINT fk_perdalote foreign key (cod_lote) references item_estoque (cod_lote) ON DELETE CASCADE ON UPDATE CASCADE,
  693.     CONSTRAINT fk_perdaprod foreign key (cod_produto) references item_estoque (cod_produto)  ON DELETE CASCADE ON UPDATE CASCADE
  694. );
  695.  
  696. -- INSERT INTO perda ( seq , cod_lote, cod_produto, id_estoque, cpf_gerente , dia , quantidade_perdida , motivo)
  697.  
  698.  
  699. -- TABELA DE VEICULO xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  700.  
  701. CREATE TABLE veiculo (
  702.  
  703.     placa char(7),
  704.     seq_filial char(4) not null,
  705.     CNPJ_matriz char(14) not null,
  706.     cod_garagem char(4) not null,
  707.     modelo varchar(15),
  708.     descricao varchar(15),
  709.     cor varchar(10),
  710.     ano year,
  711.     statuss boolean default true,
  712.     primary key (placa),
  713.     foreign key(seq_filial ) references filial(seq) ,
  714.     foreign key (CNPJ_matriz) references filial(CNPJ_Matriz),
  715.     foreign key(cod_garagem) references garagem (cod)
  716. );
  717.  
  718. -- inserindo valores na tabela veiculo OK
  719.  
  720. INSERT INTO veiculo ( placa , seq_filial , CNPJ_matriz , cod_garagem , modelo , descricao , cor , ano , statuss ) VALUES
  721.  
  722. ( 'PEX0220 ' ,  '0001' ,  '23416393000114' , '0001' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  723. ( 'PEX2030 ' ,  '0001' ,  '23416393000114' , '0001' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  724. ( 'VET4320 ' ,  '0002' ,  '23416393000114' , '0002' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  725. ( 'VET3240 ' ,  '0002' ,  '23416393000114' , '0002' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  726. ( 'WCV0943'  ,  '0003' ,  '23416393000114' , '0003' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  727. ( 'WCV3344 ' ,  '0003' ,  '23416393000114' , '0003' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  728. ( 'HLT0032 ' ,  '0004' ,  '23416393000114' , '0004' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true),
  729. ( 'HLT3994 ' ,  '0004' ,  '23416393000114' , '0004' , 'Caminhão' , 'Mercedes-benz' , 'preto' , '2014' , true);
  730.  
  731.  
  732. -- TABELA DE GARAGEM xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  733.  
  734. CREATE TABLE garagem (
  735.  
  736.     cod char(4),
  737.     seq_filial char(4) not null ,
  738.     CNPJ_matriz char(14) not null,
  739.     descricao varchar(15),
  740.     capacidade int(3) not null,
  741.     num_veiculos_atual int(3),
  742.     primary key(cod),
  743.     foreign key(seq_filial ) references filial (seq),
  744.     foreign key (CNPJ_matriz) references filial(CNPJ_matriz)
  745.    
  746.  
  747. );
  748.  
  749. -- inserindo valores na tabela garagem OK
  750.  
  751. INSERT INTO garagem ( cod , seq_filial , CNPJ_matriz , descricao , capacidade , num_veiculos_atual ) VALUES
  752.  
  753. ( '0001' , '0001' ,  '23416393000114' , null , 4 , 2 ),
  754. ( '0002' , '0002' ,  '23416393000114' , null , 4 , 2 ),
  755. ( '0003' , '0003' ,  '23416393000140' , null , 4 , 2 ),
  756. ( '0004' , '0004' ,  '23416393000169' , null , 4 , 2 );
  757.    
  758. -- TABELA DE ESTOQUE xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx  createdyes 13
  759.  
  760. CREATE TABLE estoque (
  761.  
  762.     id char(4),
  763.     seq_filial char(7) not null,
  764.     cnpj_matriz char(14) not null,
  765.     descricao varchar(80),
  766.     dt_ultima_entrada date,
  767.     primary key (id),
  768.     foreign key (seq_filial) references filial (seq),
  769.     foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  770.    
  771. );
  772.  
  773.  
  774. -- inserindo valores na tabela estoque OK
  775.  
  776. INSERT INTO estoque ( id , seq_filial , cnpj_matriz , descricao , dt_ultima_entrada ) VALUES
  777.  
  778. ( '0001' , '0001' ,  '23416393000114' , null , '2018-01-04'),
  779. ( '0002' , '0002' ,  '23416393000114' , null , '2018-01-04'),
  780. ( '0003' , '0003' ,  '23416393000140' , null , '2018-01-04'),
  781. ( '0004' , '0004' ,  '23416393000169' , null , '2018-01-04');
  782.  
  783.  
  784. -- TABELA DE LOTE createdyes 13
  785.  
  786. CREATE TABLE lote (
  787.    
  788.     cod char(4),
  789.     cod_pedido_fornecedor char(4) not null,
  790.     descricao varchar(30),
  791.     data_chegada date not null,
  792.     primary key( cod) ,
  793.     foreign key (cod_pedido_fornecedor) references pedido_fornecedor (cod)
  794.  
  795. );
  796.  
  797. -- INSERT INTO lote ( cod, cod_pedido_fornecedor, descricao , data_chegada)
  798.  
  799.        
  800.  
  801. -- TABELA DE ITEM DE ESTOQUE createdyes 13
  802.  
  803. CREATE TABLE item_estoque (
  804.    
  805.     seq char(4),
  806.     cod_lote char(4),
  807.     id_estoque char(4),
  808.     cod_produto char(4),
  809.     id_avaria char(4) not null,
  810.     id_prateleira char(4) not null,
  811.     data_validade date not null,
  812.     data_fabricacao date not null,
  813.     data_entrada date not null,
  814.     valor_compra float CHECK (valor_compra > 0),
  815.     quantidade int CHECK (quantidade > 0),
  816.     primary key (seq),
  817.     foreign key (cod_lote) references lote (cod),
  818.     foreign key (id_estoque) references estoque (id),
  819.     CONSTRAINT fk_produtoestoque foreign key ( cod_produto ) references produto_ref( cod) ON DELETE CASCADE ON UPDATE CASCADE,
  820.     foreign key (id_avaria ) references avaria ( id),
  821.     foreign key (id_prateleira ) references prateleira ( codigo)
  822.    
  823. );
  824. -- INSERT INTO item_estoque (cod_lote, id_estoque , cod_produto , id_avaria , id_prateleira , data_validade ,
  825. /* data_fabricacao , data_entrada , valor_compra, quantidade)  
  826. */
  827.  
  828.  
  829.    
  830. -- TABELA MAQUINA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  831.  
  832. CREATE TABLE maquina (
  833.  
  834.     id char(4),
  835.     id_estoque char(4) not null,
  836.     id_operador char(11) not null,
  837.     ano year ,
  838.     combustivel varchar(30),
  839.     modelo varchar(30),
  840.     capacidade float , -- CAPACIDADE EM KG
  841.     elevavao_max float , -- ELEVAVAO EM METROS
  842.     garantia date,
  843.     tipo varchar(30),
  844.     comprimento float , -- COMPRIMENTO EM METROS
  845.     primary key (id),
  846.     foreign key (id_estoque) references estoque (id),
  847.     foreign key (id_operador) references estoquista (cpf)
  848. );
  849.  
  850. -- inserindo valores na tabela maquina OK
  851.  
  852. INSERT INTO maquina ( id , id_estoque , id_operador , ano, combustivel , modelo , capacidade , elevavao_max ,
  853. garantia , tipo , comprimento ) VALUES
  854.  
  855. ( '0001' , '0001' , '77491222226' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  856. ( '0002' , '0002' , '57859332507' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  857. ( '0003' , '0003' , '16565525749' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 ),
  858. ( '0004' , '0004' , '98243208909' , '2014' , 'diesel', null , 600 , 5 , '2019-02-02' , 'empilhadeira' , 2.20 );
  859.  
  860.  
  861. -- TABELA DE AVARIA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  862.  
  863. CREATE TABLE avaria (
  864.    
  865.     id char(4),
  866.     causa varchar(20) not null,
  867.     preco float(3) CHECK ( preco > 0 ),
  868.     obs varchar(40),
  869.     primary key(id)
  870.    
  871. );
  872.  
  873. -- inserindo valores na tabela avaria OK
  874.  
  875. INSERT INTO avaria (id , causa , preco , obs ) VALUES
  876.  
  877. ('0001' , 'Queda' , 30 , null ),
  878. ('0002' , 'Queda' , 10 , null ),
  879. ('0003' , 'Queda' , 200 , null ),
  880. ('0004' , 'Queda' , 32.2 , null ),
  881. ('0005' , 'Queda' , 230 , null ),
  882. ('0006' , 'Queda' , 92.2 , null );
  883.  
  884. -- TABELA DE PRATELEIRA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  885.  
  886. CREATE TABLE prateleira (
  887.  
  888.     codigo char(4),
  889.     altura float(2) not null,
  890.     comprimento float(2) not null,
  891.     posicao_nivel char(2),
  892.     primary key(codigo)
  893.  
  894. );
  895.  
  896. -- inserindo valores na tabela prateleira  OK
  897.  
  898. INSERT INTO prateleira ( codigo , altura , comprimento , posicao_nivel ) VALUES
  899.  
  900. ('0001' , 5 , 10 , 'A1' ),
  901. ('0002' , 5 , 10 , 'A2' ),
  902. ('0003' , 5 , 10 , 'A3' ),
  903. ('0004' , 5 , 10 , 'A4' ),
  904. ('0005' , 5 , 10 , 'A5' ),
  905. ('0006' , 5 , 10 , 'B1' ),
  906. ('0007' , 5 , 10 , 'B2' ),
  907. ('0008' , 5 , 10 , 'B3' ),
  908. ('0009' , 5 , 10 , 'B4' ),
  909. ('0010' , 5 , 10 , 'B5' ),
  910. ('0011' , 5 , 10 , 'C1' ),
  911. ('0012' , 5 , 10 , 'C2' ),
  912. ('0013' , 5 , 10 , 'C3' ),
  913. ('0014' , 5 , 10 , 'C4' ),
  914. ('0015' , 5 , 10 , 'C5' );
  915.  
  916. -- TABELA DE NCM DE PRODUTO createdyes 13
  917.  
  918. CREATE TABLE NCM (
  919.    
  920.     id char(4),
  921.     descricao varchar(40),
  922.     cod_mercosul char(9) not null,
  923.     primary key(id)
  924.  
  925. );
  926.  
  927. -- inserindo valores na tabela NCM OK
  928.  
  929. INSERT INTO NCM ( id , descricao , cod_mercosul) VALUES
  930.  
  931. ('0001', ' ' , '000000001'),
  932. ('0002' , ' ' , '000000002'),
  933. ('0003' , ' ', '000000003'),
  934. ('0004' , ' ', '000000004'),
  935. ('0005', ' ' , '000000005');
  936.  
  937. -- TABELA DE UNIDADE DE PRODUTO  createdyes 13
  938.  
  939. CREATE TABLE unidade (
  940.  
  941.     cod char(4),
  942.     descricao varchar(30),
  943.     sigla char(2) not null,
  944.     primary key(cod)
  945.    
  946.    
  947. );
  948.  
  949. -- inserindo valores na tabela unidade  OK
  950.  
  951. INSERT INTO unidade (cod, descricao , sigla) VALUES
  952.  
  953. ('0001', 'quilogramas', 'kg'),
  954. ('0002' , 'mililitros', 'mL'),
  955. ('0003', 'gramas' , 'g'),
  956. ('0004', 'litros' , 'L'),
  957. ('0005', 'miligramas' , 'mg');
  958.  
  959.  
  960. -- TABELA DE CATEGORIA DE PRODUTO createdyes 13
  961.  
  962. CREATE TABLE categoria (
  963.    
  964.     cod char(4),
  965.     descricao varchar(30) not null,
  966.     primary key (cod)
  967.  
  968. );
  969.  
  970. -- inserindo valores na tabela categoria OK
  971.  
  972. INSERT INTO categoria ( cod , descricao ) VALUES
  973.  
  974. ('0001', 'Condimentos' ),
  975. ('0002' , 'Laticinios'),
  976. ('0003', 'HortiFruti'),
  977. ('0004' , 'Conservas'),
  978. ('0005', 'Limpeza'),
  979. ('0006' , 'Bebidas Alcoolicas'),
  980. ('0007' , 'Bebidas nao Alcoolicas'),
  981. ('0008' , 'Graos e Cereais');
  982.  
  983. -- TABELA DE SUBCATEGORIA DE PRODUTO createdyes 13
  984.  
  985. CREATE TABLE subcategoria (
  986.  
  987.     cod char(4),
  988.     cod_categoria char(4) not null,
  989.     descricao varchar(30) not null,
  990.     primary key(cod),
  991.     foreign key (cod_categoria) references categoria(cod)
  992.  
  993. );
  994.  
  995. -- inserindo valores na tabela subcategoria OK
  996.  
  997. INSERT INTO subcategoria ( cod , cod_categoria , descricao ) VALUES
  998.  
  999. ('0001' , '0001' , 'Vinagres'),
  1000. ('0002' , '0001' , 'Temperos'),
  1001. ('0003' , '0001' , 'Sal' ),
  1002. ('0004' , '0001', 'Azeites'),
  1003. ('0005' , '0001', 'Oleos'),
  1004. ('0006' , '0001', 'Especiarias'),
  1005. ('0007' , '0002', 'Leites'),
  1006. ('0008' , '0002', 'Iogurtes'),
  1007. ('0009' , '0002', 'Fermentados'),
  1008. ('0010' , '0002', 'Queijos'),
  1009. ('0011' , '0003', 'Ovos'),
  1010. ('0012' , '0003', 'Frutas secas'),
  1011. ('0013' , '0003', 'Legumes'),
  1012. ('0014' , '0004' , 'Frutas'),
  1013. ('0015' , '0004', 'Peixes'),
  1014. ('0016' , '0004', 'Vegetais'),
  1015. ('0017' , '0004', 'Cogumelos'),
  1016. ('0018' , '0005', 'Detergente'),
  1017. ('0019' , '0005', 'Desinfetante'),
  1018. ('0020' , '0005', 'Sabao em po'),
  1019. ('0021' , '0005', 'Sabao em barra'),
  1020. ('0022' , '0005', 'Amaciante');
  1021.  
  1022.  
  1023. -- TABELA DE MARCA DE PRODUTO createdyes 13
  1024.  
  1025. CREATE TABLE marca (
  1026.  
  1027.     cod char(4),
  1028.     descricao varchar(40),
  1029.     primary key(cod)
  1030.  
  1031. );
  1032.  
  1033. -- inserindo valores na tabela marca  OK
  1034.  
  1035. INSERT INTO marca ( cod , descricao ) VALUES
  1036.  
  1037. ('0001', 'Sadia'),
  1038. ('0002' , 'Knorr'),
  1039. ('0004' , 'Camponesa'),
  1040. ('0005' , 'Kicaldo'),
  1041. ('0006' , 'Vitarela'),
  1042. ('0007' , 'Bauduco'),
  1043. ('0008', 'OMO'),
  1044. ('0009' , 'Dona Benta'),
  1045. ('0010', 'Nestle');
  1046.  
  1047.  
  1048. -- TABELA DE FORNECEDOR xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1049.  
  1050. CREATE TABLE fornecedor (
  1051.  
  1052.     cod char(4),
  1053.     nome varchar(20) not null,
  1054.     CNPJ char(14) not null,
  1055.     rua varchar(20),
  1056.     bairro varchar(15),
  1057.     CEP char(8),
  1058.     estado varchar(15) not null,
  1059.     ativo boolean default true,
  1060.     primary key(cod)
  1061. );
  1062.  
  1063. -- inserindo valores na tabela fornecedor OK
  1064.  
  1065. INSERT INTO fornecedor ( cod , nome , CNPJ , rua , bairro , CEP , estado , ativo ) VALUES
  1066.  
  1067. ('0001' , 'Sadia'     , '55274471000180' , 'Rua valadares' , 'ipsep', '54330315' , 'Pernambuco' , true ) ,
  1068. ('0002' , 'Pampers'   , '26724671000180' , 'Rua cartomante' , 'ibura', '54202010' , 'Pernambuco' , true ) ,
  1069. ('0003' , 'Vitarela'  , '21712241000162' , 'Rua maniac' , 'algodão', '54215322' , 'São paulo' , true ) ,
  1070. ('0004' , 'Coca-cola' , '26804531000180' , 'Rua argola' , 'vale tinhaem ', '51215020' , 'Rio de janeiro' , true ) ,
  1071. ('0005' , 'Helmans'   , '77411981000180' , 'Rua sartre' , 'gitacity ', '44650201' , 'São paulo' , true ),
  1072. ('0006' , 'Bombril'   , '53686527000188' , 'Rua 3' , 'Varzea' , '50980320' , 'Recife' , true );
  1073.  
  1074.  
  1075. -- TABELA DE TELEFONE DE FORNECEDOR xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1076.  
  1077. CREATE TABLE telefone_fornecedor(
  1078.    
  1079.     seq char(4) ,
  1080.     cod_fornecedor char(4),
  1081.     telefone char(11),
  1082.     primary key(seq),
  1083.     CONSTRAINT fk_forn foreign key(cod_fornecedor) references fornecedor (cod) ON DELETE CASCADE ON UPDATE CASCADE
  1084.  
  1085. );
  1086.  
  1087. -- inserindo valores na tabela telefone_fornecedor OK
  1088.  
  1089. INSERT INTO telefone_fornecedor ( seq , cod_fornecedor, telefone) VALUES
  1090.  
  1091. ('0001' ,'0001' , '8133115544'),
  1092. ('0002' ,'0002' ,  '8133468952'),
  1093. ('0003' ,'0003' , '1140025632'),
  1094. ('0004' ,'0004', '1432456895'),
  1095. ('0005' , '0005', '1121452062');
  1096.  
  1097. -- TABELA  DE PRODUTO REF createdyes 13
  1098.  
  1099. CREATE TABLE produto_ref (
  1100.  
  1101.     cod char(4),
  1102.     id_unidade char(4),
  1103.     id_marca char(4),
  1104.     id_ncm char(4),
  1105.     id_categoria char(4),
  1106.     id_subcategoria char(4),
  1107.     id_fornecedor char(4),
  1108.     qtd_estoque int ,
  1109.     ICMS float,
  1110.     CST char(3),
  1111.     preco_por_tabela float,
  1112.     cod_barra char(13) NULL,
  1113.     freq_pedido float NULL,
  1114.     descricao varchar(30),
  1115.     qtd_min int,
  1116.     qtd_total_estoque int,
  1117.     preco_ult_compra float,
  1118.     primary key (cod),
  1119.     foreign key (id_unidade) references unidade (cod),
  1120.     foreign key (id_marca) references marca (cod),
  1121.     foreign key (id_ncm) references ncm (id),
  1122.     foreign key (id_categoria) references categoria (cod),
  1123.     foreign key (id_subcategoria) references subcategoria (cod),
  1124.     foreign key (id_fornecedor) references fornecedor (cod)
  1125.  
  1126. );
  1127.  
  1128. -- INSERT INTO profuto_ref (cod, id_unidade , id_marca , id_ncm , id_categoria, id_subcategoria, id_fornecedor , qtd_estoque ,
  1129. /* ICMS , CST , preco_por_tabela , cod_barra , freq_pedido , descricao , qtd_min, qtd_total_estoque , preco_ult_compra)
  1130. */
  1131.  
  1132. -- TABELA DE INCIDENTE  xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1133.  
  1134. CREATE TABLE incidente (
  1135.  
  1136.     cod char(4),
  1137.     seq_entrega char(4) not null,
  1138.     dataa date not null,
  1139.     relatorio varchar(200),
  1140.     hora time not null,
  1141.     primary key(cod),
  1142.     foreign key ( seq_entrega) references entrega (seq)
  1143.  
  1144. );
  1145.  
  1146. -- inserindo valores na tabela incidente OK
  1147.  
  1148. INSERT INTO incidente (cod , seq_entrega , dataa, relatorio , hora ) VALUES
  1149.  
  1150. ('0001' , '0003' , '2016-04-09 ' , ' Tentativa de assalto ' , '18:06:00' ),
  1151. ('0002' , '0005' , '2016-04-09 ' , ' Tentativa de assalto ' , '13:34:00' ),
  1152. ('0003' , '0006' , '2016-04-02 ' , ' Tentativa de assalto ' , '06:32:00' );
  1153.  
  1154. -- TABELA DOCS xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1155.  
  1156. CREATE TABLE docs (
  1157.    
  1158.     seq char(4),
  1159.     cod_incidente char(4),
  1160.     docs varchar(20),
  1161.     primary key (seq),
  1162.     CONSTRAINT fk_incidente foreign key (cod_incidente) references incidente (cod ) ON DELETE CASCADE ON UPDATE CASCADE
  1163. );
  1164.  
  1165.  -- inserindo valores na tabela docs OK
  1166.  
  1167. INSERT INTO docs ( seq , cod_incidente , docs ) VALUES
  1168.  
  1169. ('0001' , '0001', null ) ,
  1170. ('0002' ,'0002' , null ) ,
  1171. ('0003' ,'0003' , null);
  1172.  
  1173. -- TABELA DE PAGAMENTO  createdyes 13
  1174.  
  1175. CREATE TABLE pagamento (
  1176.    
  1177.     cod char(4),
  1178.     id_fatura char(4) not null,
  1179.     cod_compra char(4) not null,
  1180.     cod_tipo_pagamento char(4) not null,
  1181.     valor_pago float CHECK ( valor_pago > 0 ),
  1182.     dia date not null,
  1183.     statos boolean default true ,
  1184.     tipo_pagamento enum ('Cartao credito', 'Cartao Debito', 'Boleto'),
  1185.     primary key (cod),
  1186.     foreign key (id_fatura) references fatura (id),
  1187.     foreign key (cod_compra) references compra (cod),
  1188.     foreign key (cod_tipo_pagamento) references tipo_pagamento ( cod)
  1189.    
  1190. );
  1191.  -- INSERT INTO pagamento ( cod, id_fatura ,cod_compra , cod_tipo_pagamento  , valor_pago , dia ,  statos, tipo_pagamento ) VALUES
  1192.  
  1193.  -- TABELA DE TIPO DE PAGAMENTO createdyes 13
  1194.  
  1195. CREATE TABLE tipo_pagamento (
  1196.    
  1197.     cod char(4),
  1198.     descricao varchar(30),
  1199.     primary key(cod)
  1200.  
  1201.  );
  1202.  
  1203.  -- inserindo valores na tabela tipo_pagamento  OK
  1204.  
  1205. INSERT INTO tipo_pagamento (cod, descricao ) VALUES
  1206. ('0001' , 'Boleto Bancario'),
  1207. ('0002' , 'Cartao de Credito'),
  1208. ('0003' , 'Cartao de Debito');
  1209.  
  1210.  
  1211.  
  1212. -- TABELA DE FATURA xxxxxxxxxxxxxxxxxxxxxxxxDONExxxxxxxxxxxxxxxxxxxxx createdyes 13
  1213.  
  1214. CREATE TABLE fatura (
  1215.  
  1216.     id char(4),
  1217.     cod_pedido_fornecedor char(4),
  1218.     data_vencimento date not null,
  1219.     valor_pago_atual float CHECK (valor_pago_atual > 0 ),
  1220.     valor_total_final float CHECK (valor_total_final > 0),
  1221.     data_emissao date not null,
  1222.     statos boolean default true,
  1223.     data_paga date,
  1224.     multa float,
  1225.     primary key (id),
  1226.     foreign key (cod_pedido_fornecedor) references pedido_fornecedor (cod)
  1227.  
  1228. );
  1229. -- inserindo valores na tabela fatura
  1230.  
  1231. # INSERT INTO fatura ( id , cod_pedido_fornecedor , data_vencimento , valor_pago_atual, valor_total_final ,
  1232. # data_emissao , statos , data_paga , multa )
  1233.  
  1234.    
  1235. -- TABELA DE NOTA FISCAL createdyes 13
  1236.  
  1237. CREATE TABLE nota_fiscal (
  1238.  
  1239.     NFE char(9),
  1240.     ICMS float not null,
  1241.     valor_total float not null CHECK ( valor_total > 0 ),
  1242.     valor_total_desconto float CHECK ( valor_total_desconto >= 0 ),
  1243.     dia date not null,
  1244.     valor_frete float,
  1245.     primary key (NFE)
  1246. );
  1247.  
  1248. --  inserindo valores na tabela nota_fiscal OK
  1249.  
  1250. INSERT INTO nota_fiscal (NFE , ICMS , valor_total, valor_total_desconto, dia , valor_frete) VALUES
  1251.  
  1252. ('111111109' ,  0.04 , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1253. ('111111104' ,  0.06 , 35.80 , 35.80, '2017-10-21' , 7.90),
  1254. ('111111113' ,  0.04 , 50.21 , 49.95 , '2012-03-27' , 10.32),
  1255. ('111111105' ,  0.06 , 173.98, 173.98 , '2010-06-13' , 8.50),
  1256. ('111111107' ,  0.02 , 50.43 , 50.43 , '2002-04-01' , 2.21),
  1257. ('111111108' ,  0.03 , 283.10 , 279.50 , '2011-11-11' , 4.30),
  1258. ('111111139' ,  0.02 , 123.54 , 111.20 , '2016-11-12' , 6.80),
  1259. ('111111199' ,  0.02 , 12.99 , 12.99 , '2016-11-13' , 8.30),
  1260. ('111111129' ,  0.03 , 346.10 , 336.10 , '2016-11-10' , 2.12);
  1261.    
  1262. -- TABELA DA NOTA FISCAL FORNECEDOR createdyes 13
  1263.  
  1264. CREATE TABLE nota_fiscal_fornecedor (
  1265.  
  1266.     NFE char(9),
  1267.     cod_pagamento char(4) not null,
  1268.     CFOP char(8) not null,
  1269.     IPI float,
  1270.     primary key(NFE),
  1271.     CONSTRAINT fk_ntfiscalfornecedor foreign key (NFE) references nota_fiscal (NFE) ON DELETE CASCADE ON UPDATE CASCADE,
  1272.     foreign key (cod_pagamento) references pagamento (cod)
  1273.  );
  1274.  
  1275.  -- NOTA FISCAL FORNEEDOR INCOMPLETO
  1276. INSERT INTO nota_fiscal_fornecedor (NFE, cod_pagamento , CFOP , IPI ) VALUES
  1277.  
  1278. ('111111109' ,  NULL , 143.98 , 120 , '2016-11-12' , 3.78),
  1279. ('111111104' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1280. ('111111105' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1281. ('111111145' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1282. ('111111184' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1283. ('111111110' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1284. ('111111133' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78),
  1285. ('111111199' ,  NULL , 143.98 , 139.90 , '2016-11-12' , 3.78);
  1286.  
  1287. -- TABELA NOTA FISCAL COMPRA createdyes 13
  1288.  
  1289. CREATE TABLE nota_fiscal_compra (
  1290.  
  1291.     NFE char(9),
  1292.     cod_pagamento char(4),
  1293.     primary key (NFE),
  1294.     CONSTRAINT fk_ntfiscalcompra foreign key (NFE) references nota_fiscal (NFE) ON DELETE CASCADE ON UPDATE CASCADE,
  1295.     foreign key (cod_pagamento) references pagamento (cod)
  1296.  
  1297. );
  1298.  
  1299. -- inserindo valores na tabela nota_fical_compra
  1300.  
  1301. #INSERT INTO nota_fiscal_compra ( NFE , cod_pagamento ) VALUES
  1302. #('111111129' ,
  1303.  
  1304. -- TABELA DE CLIENTE  createdyes 13
  1305.  
  1306. CREATE TABLE cliente (
  1307.  
  1308.     CPF char(11),
  1309.     seq_filial char(4) not null,
  1310.     cnpj_matriz char(14) not null,
  1311.     cep char(8) not null,
  1312.     cidade varchar(30),
  1313.     numero char(11),
  1314.     descricao varchar(30),
  1315.     valor_credito float,
  1316.     p_nome varchar(20) not null,
  1317.     m_nome varchar(20) ,
  1318.     u_nome varchar(30) not null,
  1319.     rg char(7) not null,
  1320.     senha varchar(12) not null default '123456',
  1321.     tem_clube_desconto boolean default false,
  1322.     data_cadastro date,
  1323.     email varchar(40) not null,
  1324.     data_nascimento date not null,
  1325.     primary key (CPF),
  1326.     foreign key (seq_filial) references filial (seq ),
  1327.     foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  1328.    
  1329. );
  1330.  
  1331.  
  1332. -- !!!!!!!!!!!!!!!!!!!!!! FALTA INCLUIR O CNPJ NAS TUPLAS !!!!!!!!!!!!!!!!
  1333.  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
  1334.  
  1335. ('54501233290' , '0001' , '23416393000114' , '52291045' , 'Recife' , '11111111111' ,  'Rua Jaguaribara' , 1200.00 , 'Melissa' , 'Andreia' , 'Nascimento', '1908234', false , '2016-02-12', 'manasc@gmail.com' , '1999-06-13'),
  1336. ('25251145314' , '0002' , '23416393000114', '50999321' , 'Olinda' , null, 'Rua de Saão Bento' , 0 , 'Marcos' , 'Andre' , 'Marques' , '9123786' , 'xxx9' , false , '2015-03-11' , 'marcossantos@hotmail.com' , '1980-03-25' ),
  1337. ('13345509287' , '0001' , '23416393000114', '50348567' , 'Recife' , null , 'Rua Real da Torre ' , 0, 'Fatima' , 'Caixias' , 'Laffaiete' , '1866630' , '1233' , false , '2017-02-11' , 'falcaix@gmail.com' , '1972-09-09'),
  1338. ('77658476358' , '0001' , '23416393000114', '63900435' , 'Ceará' , null , 'Rua Chile' , 0 , 'Renato' , 'Murilo' , 'Dias' , '1266839' , '34g4' , false , '2017-07-04', 'murilodias@gmail.com' , '1989-12-29'),
  1339. ('50519774647' , '0002' , '23416393000114', '56332078' , 'Petrolina' ,  null, 'Rua Quarenta e Seis' , 22.30 , 'Joaquim', 'Luiz' , 'Campos' , '287101988' , '88uh' , true , '2016-04-04' , 'uizjoaquim@hotmail.com' , '1990-04-30'),
  1340. ('79317880797' , '0001' , '23416393000114', '82600130' , 'Curitiba' , null , 'Rua Bernardo Rosenmann' , 0, 'Alana' , 'Rodrigues', 'Mello',  '2368088' ,  '34f4' , true , '2016-09-11' , 'alana_rodriques@gmail.com' , '1993-06-06'),
  1341. ('52125191105' , '0002' , '23416393000114', '77820026' , 'Araguaina' , null, 'Rua 16' , 0, 'Luana', 'Barbosa' , 'Pinto' , '1994566' , '9jf4' , true , '2016-09-11' , 'luaninha_babrbosa@gmail.com' , '1996-06-06'),
  1342. ('50130428361' , '0001' , '23416393000114', '77016638' , 'Palmas' , null , 'Quadra 509 Sul Alameda 7' , 0, 'Agatha', 'Vasconcelos' , 'Belarmino' , '4526174' , 'f56g' , true , '2016-03-04', 'agatinha_bb@gmail.com' , '1999-09-09'),
  1343. ('96468793068' , '0001' , '23416393000114', '49069186' , 'Aracaju', null, 'Rua do Sol' , 0 , 'Camila' , 'Castro' , 'Raimundo' , '3199788' , 'kj004' , true , '2016-09-18', 'camila_racastro@gmail.com' , '1992-02-20'),
  1344. ('16512268903' , '0002', '23416393000114', '72876134' , 'Valparaíso de Goiás' , null, 'Quadra 37' , 23.33, 'Valkiria' , 'Queiroz' , 'Calado' , '4241822' , 'kd3io4' , true , '2016-02-12' , 'valqueiros@outlook.com' , '1960-03-07'),
  1345. ('07617589689' , '0002' , '23416393000114', '89280577' , 'São Bento do Sul' , null, 'Rua Zanzibar' , 0, 'Angelica' , 'Meneses' , 'da Silva' , '4764955' , 'i4hfi4h' , false , '2017-02-05' , 'angelica_mene@outlook.com' , '1992-12-11');
  1346.  
  1347.  
  1348. -- TABELA DE TELEFONE DE CLIENTE createdyes 13
  1349.  # ----------------------ALTERANDO VALORES ---------------------
  1350. CREATE TABLE telefone_cliente (
  1351.    
  1352.     CPF char(11) not null,
  1353.     telefone char(10),
  1354.     CONSTRAINT telefone_cliente_pk primary key (CPF, telefone),
  1355.     CONSTRAINT fk_telefonecliente foreign key (CPF) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1356. );
  1357.  
  1358. -- inserindo valores na tabela telefone_cliente
  1359.  
  1360.  INSERT INTO telefone_cliente ( CPF, telefone) VALUES
  1361.  
  1362.  ('54501233290' , '8134564432'),
  1363.  ('25251145314' , '8199890765'),
  1364.  ('77658476358' , '8599690359'),
  1365.  ('07617589689' , '4899097820'),
  1366.  ('07617589689' , '8191913012'),
  1367.  ('96468793068' , '7934876650'),
  1368.  ('96468793068' , '7988786534'),
  1369.  ('50519774647' , '8133234567');
  1370.  
  1371.  
  1372. -- TABELA DE SUGESTAO createdyes 13
  1373.  
  1374. CREATE TABLE sugestao (
  1375.    
  1376.     CPF_cliente char(11) not null,
  1377.     id char(4),
  1378.     dia date,
  1379.     descricao varchar(30) not null,
  1380.     primary key (id),
  1381.     CONSTRAINT fk_sugestao foreign key (CPF_cliente) references cliente (CPF) ON DELETE CASCADE ON UPDATE CASCADE
  1382. );
  1383.  
  1384. -- inserindo valores na tabela sugestao
  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. -- inserindo valores na tabela reclamacao
  1414.  
  1415. INSERT INTO reclamacao ( CPF_cliente , id , motivo, data_ocorrido, data_reclamacao) VALUES
  1416.  
  1417. ('54501233290' , '0001' , 'atendimento muito demorado', '2016-03-09' , '2016-03-13'),
  1418. ('54501233290' , '0002' , 'produto estava perto de vencer', '2016-03-09' , '2016-03-13'),
  1419. ('54501233290' , '0003' , 'o entregador nao chegou', '2016-03-01' , '2016-03-20'),
  1420. ('54501233290' , '0004' , 'erraram o endereco de entrega', '2016-03-09' , '2016-03-13'),
  1421. ('54501233290' , '0005' , 'atendimento muito demorado', '2016-03-09' , '2016-03-10'),
  1422. ('54501233290' , '0006' , 'site fora do ar', '2016-04-01' , '2016-04-01'),
  1423. ('54501233290' , '0007' , 'atendimento muito demorado', '2016-03-09' , '2016-03-13');
  1424.  
  1425.  
  1426. -- TABELA DE PROMOCAO createdyes 13
  1427.  
  1428. CREATE TABLE promocao (
  1429.  
  1430.     cod char(4),
  1431.     seq_filial char(4) not null,
  1432.     cnpj_matriz char(14) not null,
  1433.     nome varchar(30),
  1434.     data_inicio date not null,
  1435.     percentual_reducao float not null CHECK ( percentual_reducao > 0 ),
  1436.     data_fim date,
  1437.     obs varchar(30),
  1438.     descricao varchar(50),
  1439.     primary key (cod),
  1440.     foreign key (seq_filial ) references filial (seq),
  1441.     foreign key (cnpj_matriz) references filial(CNPJ_Matriz)
  1442.  
  1443. );
  1444.  
  1445. -- inserindo valores na tabela promocao OK
  1446.  
  1447. INSERT INTO promocao (cod, seq_filial , cnpj_matriz , nome , data_inicio, percentual_reducao , data_fim, obs, descricao) VALUES
  1448.  
  1449. ('0001' , '0001 ',  '23416393000114', 'Um barato no pedaco' , '2017-02-05', 0.13 , '2017-03-05' , 'n inclui importados' , 'promocao para laticinios'),
  1450. ('0002' , '0001' ,  '23416393000114', 'Queima de estoque' , '2016-12-22' , 0.33 , '2016-12-31' , NULL , NULL),
  1451. ('0003' , '0002',  '23416393000114','Mes da verdura' , '2017-08-12' , 0.26 , '2017-10-12' , 'n inclui conservas' , 'promocao para hortifruti' ),
  1452. ('0004' , '0002' ,  '23416393000114', 'Mes da conserva' , '2017-11-20' , 0.21 , '2017-12-20', NULL , 'apenas conservas' ),
  1453. ('0005 ', '0001' , '23416393000114', 'Desinfetantes em queima' , '2018-01-02' , 0.24 , '2018-02-02' , NULL , 'apenas desinfetantes'),
  1454. ('0006' , '0002' , '23416393000114', 'Promocao de amaciante' , '2017-09-15' , 0.12, '2017-11-15' , NULL , 'amaciantes nacionais'),
  1455. ('0007' , '0001' , '23416393000114', 'Laticinios vao a loucura' , '2018-01-02', 0.29, '2018-03-02' , NULL , 'reducao de preco laticinios'),
  1456. ('0008' , '0002' ,  '23416393000114','Promocao de Sabao em po' , '2017-06-15' , 0.19 , '2017-07-15' , NULL , 'promocao sabao em po');
  1457.  
  1458. -- TABELA DE PEDIDO FORNECEDOR createdyes 13
  1459.  
  1460. CREATE TABLE pedido_fornecedor (
  1461.    
  1462.     cod char(4),
  1463.     CPF_gerente char(11) not null,
  1464.     total_desconto float CHECK ( total_desconto >= 0 ),
  1465.     valor_total_IPI float CHECK ( valor_total_IPI >= 0 ),
  1466.     CFOP char(4) not null,
  1467.     valor_total float CHECK ( valor_total >= 0),
  1468.     dia date not null,
  1469.     statos boolean default true,
  1470.     valor_frete float CHECK (valor_frete >= 0),
  1471.     primary key (cod),
  1472.     foreign key (CPF_gerente) references gerente (CPF)
  1473. );
  1474.  
  1475. -- inserindo valores na tabela pedido_fornecedor OK
  1476.  
  1477.  INSERT INTO pedido_fornecedor ( cod, CPF_gerente , total_desconto , valor_total_IPI, CFOP, dia , statos, valor_frete ) VALUES
  1478.  
  1479. ('0001' , '96202875763' , 12380.00, 354.20 , '0001', '2017-12-09' , true , 12.90),
  1480. ('0002', '96202875763' , 3456.40 , 123.20 , '0002', '2017-11-09' , true , 10.30),
  1481. ('0003' , '96202875763' , 2280.25 , 220.00,'0003',  '2017-06-13', true , 28.50),
  1482. ('0004' , '96202875763' , 12200.00, 123.99,'0004',  '2017-07-04', true , 9.89),
  1483. ('0005' , '96202875763' , 990.00 , 19.89,  '0005',  '2016-12-09', true , 12.43),
  1484. ('0006' , '96202875763' , 5660.00, 56.70 , '0006', '2015-08-27' , true , 6.98),
  1485. ('0007' , '96202875763' , 2890.00 , 35.47 , '0007', '2016-04-12' , true , 10.20),
  1486. ('0008' , '96202875763' , 1873.20 , 190.00 ,'0008' , '2017-01-04' , true , 8.33),
  1487. ('0009' , '96202875763' , 2348.80, 111.10 , '0009' ,'2017-06-09' , true , 10.22),
  1488. ('0010' , '02123011878' , 1300.00, 132.30 , '0010','2017-08-27' , true , 11.30);
  1489.  
  1490. -- TABELA DE ITEM PEDIDO createdyes 13
  1491.  
  1492. CREATE TABLE item_pedido (
  1493.  
  1494.     seq char(4),
  1495.     cod_produto_ref char(4) not null,
  1496.     cod_pedido_fornecedor char(4) not null,
  1497.     quantidade int not null CHECK (quantidade > 0) ,
  1498.     preco_unitario float  not null CHECK (preco_unitario  > 0),
  1499.     primary key (seq),
  1500.     foreign key (cod_produto_ref) references produto_ref (cod),
  1501.     foreign key (cod_pedido_fornecedor) references pedido_fornecedor(cod)
  1502. );
  1503.  
  1504. -- INSERT INTO item_pedido (seq , cod_produto_ref , cod_pedido_fornecedor, quantidade , preco_unitario) VALUES
  1505.  
  1506.  
  1507. -- TABELA DE RELACIONAMENTO TEM DE FUNCIONARIO createdyes 13
  1508.  
  1509. CREATE TABLE tem (
  1510.      
  1511.     id_jornada char(4),
  1512.     id_turno char(4),
  1513.     id_dia char(4),
  1514.     CONSTRAINT tem_pk primary key (id_jornada , id_turno , id_dia ),
  1515.     CONSTRAINT tem_id_jornada foreign key (id_jornada) references jornadatrabalho(id),
  1516.     CONSTRAINT tem_id_turno foreign key (id_turno) references turno(cod),
  1517.     CONSTRAINT tem_id_dia foreign key (id_dia) references dia (sequencial)
  1518.    
  1519. );
  1520.  
  1521.  
  1522. -- inserindo valores na tabela tem
  1523.  
  1524. INSERT INTO tem (id_jornada , id_turno, id_dia ) VALUES
  1525.  
  1526. ('0001' , '0001' , '0001' ),
  1527. ('0001' , '0002' , '0002' ),
  1528. ('0001' , '0003' , '0003' ),
  1529. ('0001' , '0002' , '0004' ),
  1530. ('0001' , '0002' , '0005' ),
  1531. ('0001' , '0002' , '0006' ),
  1532. ('0001' , '0001' , '0007' ),
  1533. ('0002' , '0010' , '0001' ),
  1534. ('0002' , '0006' , '0005' ),
  1535. ('0003' , '0009' , '0006' ),
  1536. ('0004' , '0001' , '0001' );
  1537.  
  1538.  
  1539.  
  1540. -- TABELA RELACIONAMENTO REALIZA CURSO createdyes 13
  1541.  
  1542. CREATE TABLE realizacurso (
  1543.    
  1544.     seq char(4),
  1545.     cpf_fun char(11),
  1546.     id_curso char(4),
  1547.     dt_inicio date,
  1548.     dt_fim date,
  1549.     primary key (seq),
  1550.     foreign key (cpf_fun) references funcionario(CPF),
  1551.     foreign key (id_curso) references curso (id)
  1552. );
  1553.  
  1554. -- inserindo valores na tabela realiza_curso
  1555.  
  1556. INSERT INTO realizacurso ( seq , cpf_fun , id_curso , dt_inicio , dt_fim) VALUES
  1557.  
  1558. ('0001','77491222226', '2101' , '2016-02-13' , '2016-03-15' ),
  1559. ('0002', '77491222226' , '8012' , '2016-04-09' , '2016-06-09' ),
  1560. ('0003', '32568071001' , '2101' ,'2016-02-13' , '2016-03-15' ),
  1561. ('0004', '45321186898' , '8012' , '2016-04-09' , '2016-06-09' ),
  1562. ('0005', '77491222226' , '8012' , '2016-04-09' , '2016-06-09' ),
  1563. ('0006' ,'14073416260' , '8012' , '2016-04-09' , '2016-06-09' ),
  1564. ('0007', '88356795591' , '8012' , '2016-04-09' , '2016-06-09' );
  1565.  
  1566. -- TABELA DE GERENCIA DE ESTOQUE/* createdyes 13
  1567.  
  1568. CREATE TABLE gerencia_estoque (
  1569.    
  1570.     seq char(4),
  1571.     cpf_super_estoque char(11),
  1572.     id_estoque char(4),
  1573.     dt_fim date,
  1574.     dt_inicio date,
  1575.     primary key (seq),
  1576.     foreign key (cpf_super_estoque) references SupervisorEstoque (CPF),
  1577.     foreign key (id_estoque) references estoque(id)
  1578.    
  1579. );
  1580.  
  1581. -- inserindo valores na tabela gerencia_estoque
  1582.  
  1583.  INSERT INTO gerencia_estoque (seq, cpf_super_estoque, id_estoque , dt_fim, dt_inicio) VALUES
  1584.  
  1585. ('0001' ,'14073416260' , '0000001' ,'2017-03-02' ,'2016-03-02'),
  1586. ('0002', '85902755239' , '0000002' , '2017-04-15' , '2016-02-15'),
  1587. ('0003', '88356795591' , '0000003' , '2016-01-01' , '2014-02-13'),
  1588. ('0004', '14073416260' , '0000002 ' , '2013-06-22' , '2012-06-10'),
  1589. ('0005', '85902755239' , '0000003'  ,'2017-09-02', '2016-01-02' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement