Advertisement
11eimilia11

Super 1203

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