Advertisement
jvidalgz

BD_CERT2

Jul 7th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 6.50 KB | None | 0 0
  1. /*
  2. Navicat MySQL Data Transfer
  3.  
  4. Source Server         : local
  5. Source Server Version : 50524
  6. Source Host           : localhost:3306
  7. Source Database       : pauta_cert1
  8.  
  9. Target Server Type    : MYSQL
  10. Target Server Version : 50524
  11. File Encoding         : 65001
  12.  
  13. Date: 2014-07-07 11:10:15
  14. */
  15.  
  16. SET FOREIGN_KEY_CHECKS=0;
  17.  
  18. -- ----------------------------
  19. -- Table structure for categoria
  20. -- ----------------------------
  21. DROP TABLE IF EXISTS `categoria`;
  22. CREATE TABLE `categoria` (
  23.   `id_categoria` INT(3) NOT NULL,
  24.   `nombre` VARCHAR(50) DEFAULT NULL,
  25.   PRIMARY KEY (`id_categoria`)
  26. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  27.  
  28. -- ----------------------------
  29. -- Records of categoria
  30. -- ----------------------------
  31. INSERT INTO `categoria` VALUES ('1', 'indefinido');
  32. INSERT INTO `categoria` VALUES ('2', 'a plazo');
  33.  
  34. -- ----------------------------
  35. -- Table structure for contratos
  36. -- ----------------------------
  37. DROP TABLE IF EXISTS `contratos`;
  38. CREATE TABLE `contratos` (
  39.   `nro_contrato` INT(3) NOT NULL,
  40.   `dni` INT(3) NOT NULL,
  41.   `id_categoria` INT(3) NOT NULL,
  42.   `fecha_inicial` DATE DEFAULT NULL,
  43.   `fecha_final` DATE DEFAULT NULL,
  44.   PRIMARY KEY (`nro_contrato`),
  45.   KEY `dni` (`dni`),
  46.   KEY `id_categoria` (`id_categoria`),
  47.   CONSTRAINT `contratos_ibfk_1` FOREIGN KEY (`dni`) REFERENCES `trabajadores` (`dni`),
  48.   CONSTRAINT `contratos_ibfk_2` FOREIGN KEY (`id_categoria`) REFERENCES `categoria` (`id_categoria`)
  49. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  50.  
  51. -- ----------------------------
  52. -- Records of contratos
  53. -- ----------------------------
  54. INSERT INTO `contratos` VALUES ('1', '3', '1', '2014-08-01', '2014-10-30');
  55. INSERT INTO `contratos` VALUES ('2', '2', '2', '2014-01-01', '2014-06-01');
  56. INSERT INTO `contratos` VALUES ('3', '5', '2', '2014-02-15', '2014-08-15');
  57. INSERT INTO `contratos` VALUES ('4', '2', '1', NULL, NULL);
  58. INSERT INTO `contratos` VALUES ('5', '2', '1', NULL, NULL);
  59. INSERT INTO `contratos` VALUES ('6', '2', '1', NULL, NULL);
  60.  
  61. -- ----------------------------
  62. -- Table structure for departamento
  63. -- ----------------------------
  64. DROP TABLE IF EXISTS `departamento`;
  65. CREATE TABLE `departamento` (
  66.   `cod_departamento` INT(3) NOT NULL,
  67.   `nombre` VARCHAR(50) DEFAULT NULL,
  68.   `dni_coordinador` INT(3) DEFAULT NULL,
  69.   PRIMARY KEY (`cod_departamento`),
  70.   KEY `dni_coordinador` (`dni_coordinador`),
  71.   CONSTRAINT `departamento_ibfk_1` FOREIGN KEY (`dni_coordinador`) REFERENCES `trabajadores` (`dni`)
  72. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  73.  
  74. -- ----------------------------
  75. -- Records of departamento
  76. -- ----------------------------
  77. INSERT INTO `departamento` VALUES ('1', 'administracion', '1');
  78. INSERT INTO `departamento` VALUES ('2', 'finanzas', '2');
  79. INSERT INTO `departamento` VALUES ('3', 'informatica', '3');
  80.  
  81. -- ----------------------------
  82. -- Table structure for nominas
  83. -- ----------------------------
  84. DROP TABLE IF EXISTS `nominas`;
  85. CREATE TABLE `nominas` (
  86.   `id_nomina` INT(3) NOT NULL DEFAULT '0',
  87.   `nro_contrato` INT(3) DEFAULT NULL,
  88.   `fecha` DATE DEFAULT NULL,
  89.   `salario` INT(6) DEFAULT NULL,
  90.   PRIMARY KEY (`id_nomina`),
  91.   KEY `nro_contrato` (`nro_contrato`),
  92.   CONSTRAINT `nominas_ibfk_1` FOREIGN KEY (`nro_contrato`) REFERENCES `contratos` (`nro_contrato`)
  93. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  94.  
  95. -- ----------------------------
  96. -- Records of nominas
  97. -- ----------------------------
  98. INSERT INTO `nominas` VALUES ('1', '1', '2014-09-30', '200000');
  99. INSERT INTO `nominas` VALUES ('2', '1', '2014-09-30', '250000');
  100. INSERT INTO `nominas` VALUES ('3', '3', '2014-08-15', '800000');
  101.  
  102. -- ----------------------------
  103. -- Table structure for responsable_nomina
  104. -- ----------------------------
  105. DROP TABLE IF EXISTS `responsable_nomina`;
  106. CREATE TABLE `responsable_nomina` (
  107.   `id_nomina` INT(3) NOT NULL DEFAULT '0',
  108.   `nro_contrato` INT(3) NOT NULL DEFAULT '0',
  109.   `dni_responsable_nomina` INT(3) NOT NULL DEFAULT '0',
  110.   PRIMARY KEY (`id_nomina`,`nro_contrato`,`dni_responsable_nomina`),
  111.   KEY `nro_contrato` (`nro_contrato`),
  112.   KEY `dni_responsable_nomina` (`dni_responsable_nomina`),
  113.   CONSTRAINT `responsable_nomina_ibfk_1` FOREIGN KEY (`id_nomina`) REFERENCES `nominas` (`id_nomina`),
  114.   CONSTRAINT `responsable_nomina_ibfk_2` FOREIGN KEY (`nro_contrato`) REFERENCES `contratos` (`nro_contrato`),
  115.   CONSTRAINT `responsable_nomina_ibfk_3` FOREIGN KEY (`dni_responsable_nomina`) REFERENCES `trabajadores` (`dni`)
  116. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  117.  
  118. -- ----------------------------
  119. -- Records of responsable_nomina
  120. -- ----------------------------
  121. INSERT INTO `responsable_nomina` VALUES ('1', '1', '1');
  122. INSERT INTO `responsable_nomina` VALUES ('2', '2', '1');
  123. INSERT INTO `responsable_nomina` VALUES ('3', '3', '1');
  124.  
  125. -- ----------------------------
  126. -- Table structure for trabajadores
  127. -- ----------------------------
  128. DROP TABLE IF EXISTS `trabajadores`;
  129. CREATE TABLE `trabajadores` (
  130.   `dni` INT(3) NOT NULL,
  131.   `nombre` VARCHAR(50) DEFAULT NULL,
  132.   `apellidos` VARCHAR(50) DEFAULT NULL,
  133.   `telefono` INT(10) DEFAULT NULL,
  134.   `direccion` VARCHAR(50) DEFAULT NULL,
  135.   `comuna` VARCHAR(50) DEFAULT NULL,
  136.   `dni_jefe` INT(3) DEFAULT NULL,
  137.   `cod_departamento` INT(3) NOT NULL,
  138.   PRIMARY KEY (`dni`),
  139.   KEY `dni_jefe` (`dni_jefe`),
  140.   KEY `cod_departamento` (`cod_departamento`),
  141.   CONSTRAINT `trabajadores_ibfk_1` FOREIGN KEY (`dni_jefe`) REFERENCES `trabajadores` (`dni`),
  142.   CONSTRAINT `trabajadores_ibfk_2` FOREIGN KEY (`cod_departamento`) REFERENCES `departamento` (`cod_departamento`)
  143. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  144.  
  145. -- ----------------------------
  146. -- Records of trabajadores
  147. -- ----------------------------
  148. INSERT INTO `trabajadores` VALUES ('1', 'juan', 'molina', '12345', 'calle siempre viva', 'springfield', '4', '1');
  149. INSERT INTO `trabajadores` VALUES ('2', 'lalo', 'landa', '92374', 'los carrera 34', 'concepcion', '4', '2');
  150. INSERT INTO `trabajadores` VALUES ('3', 'suricate', 'africano', '99999', 'en la llanura africana', 'congo', '4', '3');
  151. INSERT INTO `trabajadores` VALUES ('4', 'pepe', 'vidal', '435657', 'basilon 123', 'concepcion', NULL, '1');
  152. INSERT INTO `trabajadores` VALUES ('5', 'alan', 'brito', '12345', 'arturo prat', 'chillan', '4', '2');
  153.  
  154. -- ----------------------------
  155. -- View structure for trabajadores_conce
  156. -- ----------------------------
  157. DROP VIEW IF EXISTS `trabajadores_conce`;
  158. CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost`  VIEW `trabajadores_conce` AS ( SELECT t.nombre, t.apellidos FROM trabajadores t JOIN contratos c ON (t.dni=c.dni) WHERE t.comuna='concepcion' GROUP BY t.nombre,t.apellidos HAVING (COUNT(c.dni) > 3)) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement