davidween

URI 2989 Script SQL

Nov 16th, 2020
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 5.03 KB | None | 0 0
  1. CREATE TABLE departamento(
  2.     cod_dep INTEGER PRIMARY KEY,
  3.     nome VARCHAR(50),
  4.     endereco VARCHAR(50)
  5. );
  6.  
  7. CREATE TABLE divisao(
  8.     cod_divisao INTEGER PRIMARY KEY,
  9.     nome VARCHAR(50),
  10.     endereco VARCHAR(50),
  11.     cod_dep INTEGER REFERENCES departamento (cod_dep)
  12. );
  13.  
  14. CREATE TABLE empregado(
  15.     matr INTEGER PRIMARY KEY,
  16.     nome VARCHAR(50),
  17.     endereco VARCHAR(50),
  18.     data_lotacao TIMESTAMP,
  19.     lotacao INTEGER,
  20.     gerencia_cod_dep INTEGER REFERENCES departamento (cod_dep),
  21.     lotacao_div INTEGER REFERENCES divisao (cod_divisao),
  22.     gerencia_div INTEGER REFERENCES divisao (cod_divisao)
  23. );
  24.  
  25. CREATE TABLE dependente(
  26.     matr INTEGER REFERENCES empregado (matr),
  27.     nome VARCHAR(50),
  28.     endereco VARCHAR(50)
  29. );
  30.  
  31. CREATE TABLE desconto(
  32.     cod_desc INTEGER PRIMARY KEY,
  33.     nome VARCHAR(50),
  34.     tipo VARCHAR(10),
  35.     valor NUMERIC
  36. );
  37.  
  38. CREATE TABLE vencimento(
  39.     cod_venc INTEGER PRIMARY KEY,
  40.     nome VARCHAR(50),
  41.     tipo VARCHAR(10),
  42.     valor NUMERIC
  43. );
  44.  
  45. CREATE TABLE emp_desc(
  46.     cod_desc INTEGER REFERENCES desconto (cod_desc),
  47.     matr INTEGER REFERENCES empregado (matr)
  48. );
  49.  
  50. CREATE TABLE emp_venc(
  51.     cod_venc INTEGER REFERENCES vencimento (cod_venc),
  52.     matr INTEGER REFERENCES empregado (matr)
  53. );
  54.  
  55.  
  56. INSERT INTO departamento VALUES
  57.     (1, 'Contabilidade', 'R. X'),
  58.     (2, 'TI', 'R. Y'),
  59.     (3, 'Engenharia', 'R. Y');
  60.  
  61. INSERT INTO divisao VALUES
  62.     (11, 'Ativo', 'R. X', 1),
  63.     (12, 'Passivo', 'R. X', 1),
  64.     (21, 'Desenvoilvimento de Projetos', 'R. Y', 2),
  65.     (22, 'Analise de Sistemas', 'R. Y', 2),
  66.     (23, 'Programacao', 'R. W', 2),
  67.     (31, 'Concreto', 'R. Y', 3),
  68.     (32, 'Calculo Estrutural', 'R. Y', 3);
  69.  
  70. INSERT INTO empregado VALUES
  71.     (9999, 'Jose Sampaio', 'R. Z', '2006-06-06T00:00:00Z', 1, 1, 12, NULL),
  72.     (33, 'Jose Maria', 'R. 21', '2006-03-01T00:00:00Z', 1, NULL, 11, 11),
  73.     (1, 'Maria Jose', 'R. 52', '2003-03-01T00:00:00Z', 1, NULL, 11, NULL),
  74.     (7, 'Yasmim', 'R. 13', '0210-07-02T00:00:00Z', 1, NULL, 11, NULL),
  75.     (5, 'Rebeca', 'R. 1', '2011-04-01T00:00:00Z', 1, NULL, 12, 12),
  76.     (13, 'Sofia', 'R. 28', '2010-09-09T00:00:00Z', 1, NULL, 12, NULL),
  77.     (27, 'Andre', 'R. Z', '2005-05-01T00:00:00Z', 2, 2, 22, NULL),
  78.     (88, 'Yami', 'R. T', '2014-02-01T00:00:00Z', 2, NULL, 21, 21),
  79.     (431, 'Joao da Silva', 'R. Y', '2011-07-03T00:00:00Z', 2, NULL, 21, NULL),
  80.     (135, 'Ricardo Reis', 'R. 33', '2009-08-01T00:00:00Z', 2, NULL, 21, NULL),
  81.     (254, 'Barbara', 'R. Z', '2008-01-03T00:00:00Z', 2, NULL, 22, 22),
  82.     (371, 'Ines', 'R. Y', '2005-01-01T00:00:00Z', 2, NULL, 22, NULL),
  83.     (476, 'Flor', 'R. Z', '2015-10-28T00:00:00Z', 2, NULL, 23, 23),
  84.     (25, 'Lina', 'R. 67', '2014-09-01T00:00:00Z', 2, NULL, 23, NULL),
  85.     (3, 'Jose da Silva', 'R. 8', '2011-01-02T00:00:00Z', 3, 3, 31, NULL),
  86.     (71, 'Silverio dos Reis', 'R. C', '2009-01-05T00:00:00Z', 3, NULL, 31, 31),
  87.     (91, 'Reis da Silva', 'R. Z', '2011-11-05T00:00:00Z', 3, NULL, 31, NULL),
  88.     (55, 'Lucas', 'R. 31', '2013-07-01T00:00:00Z', 3, NULL, 32, 32),
  89.     (222, 'Marina', 'R. 31', '2015-01-07T00:00:00Z', 3, NULL, 32, NULL),
  90.     (725, 'Angelo', 'R. X', '2001-03-01T00:00:00Z', 2, NULL, 21, NULL);
  91.  
  92. INSERT INTO dependente VALUES
  93.     (9999, 'Francisco Jose', 'R. Z'),
  94.     (88, 'Maria da Silva', 'R. T'),
  95.     (55, 'Virgulino da Silva', 'R. 31');
  96.  
  97. INSERT INTO desconto VALUES
  98.     (91, 'IR', 'V', 400),
  99.     (92, 'Plano de saude', 'V', 300),
  100.     (93, NULL, NULL, NULL);
  101.  
  102. INSERT INTO vencimento VALUES
  103.     (1, 'Salario base Analista de Sistemas', 'V', 5000),
  104.     (2, 'Salario base Contador', 'V', 3000),
  105.     (3, 'Salario Base Engenheiro', 'V', 4500),
  106.     (4, 'Salario Base Projetista Software', 'V', 5000),
  107.     (5, 'Salario Base Programador de Sistemas', 'V', 3000),
  108.     (6, 'Gratificacao Chefia Departamento', 'V', 3750),
  109.     (7, 'Gratificacao Chefia Divisao', 'V', 2200),
  110.     (8, 'Salario Trabalhador Costrucao Civil', 'V', 800),
  111.     (9, 'Auxilio Salario Familia', 'V', 300),
  112.     (10, 'Gratificacao Tempo de servico', 'V', 350),
  113.     (11, 'Insalubridade', 'V', 800),
  114.     (12, 'Gratificacao por titulacao - Doutorado', 'V', 2000),
  115.     (13, 'Gratificacao por Titularidade - Mestrado', 'v', 800);
  116.  
  117. INSERT INTO emp_desc VALUES
  118.     (91, 3),
  119.     (91, 27),
  120.     (91, 9999),
  121.     (92, 27),
  122.     (92, 71),
  123.     (92, 88),
  124.     (92, 9999);
  125.  
  126. INSERT INTO emp_venc VALUES
  127.     (1, 27),
  128.     (1, 88),
  129.     (1, 135),
  130.     (1, 254),
  131.     (1, 431),
  132.     (2, 1),
  133.     (2, 5),
  134.     (2, 7),
  135.     (2, 13),
  136.     (2, 33),
  137.     (2, 9999),
  138.     (3, 3),
  139.     (3, 55),
  140.     (3, 71),
  141.     (3, 222),
  142.     (4, 25),
  143.     (4, 476),
  144.     (5, 371),
  145.     (6, 3),
  146.     (6, 27),
  147.     (6, 9999),
  148.     (7, 5),
  149.     (7, 33),
  150.     (7, 55),
  151.     (7, 71),
  152.     (7, 88),
  153.     (7, 254),
  154.     (7, 476),
  155.     (8, 25),
  156.     (8, 91),
  157.     (9, 1),
  158.     (9, 27),
  159.     (9, 91),
  160.     (9, 135),
  161.     (9, 371),
  162.     (9, 9999),
  163.     (10, 371),
  164.     (10, 9999),
  165.     (11, 91),
  166.     (12, 3),
  167.     (12, 27),
  168.     (12, 254),
  169.     (12, 9999),
  170.     (13, 3),
  171.     (13, 5),
  172.     (13, 7),
  173.     (13, 25),
  174.     (13, 33),
  175.     (13, 88),
  176.     (13, 135);
Advertisement
Add Comment
Please, Sign In to add comment