Advertisement
LeoMonte

bvdasdfd

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