Advertisement
11eimilia11

Ate func ok MENOS veiculo

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