Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Navicat MySQL Data Transfer
- Source Server : local
- Source Server Version : 50524
- Source Host : localhost:3306
- Source Database : pauta_cert1
- Target Server Type : MYSQL
- Target Server Version : 50524
- File Encoding : 65001
- Date: 2014-07-07 11:10:15
- */
- SET FOREIGN_KEY_CHECKS=0;
- -- ----------------------------
- -- Table structure for categoria
- -- ----------------------------
- DROP TABLE IF EXISTS `categoria`;
- CREATE TABLE `categoria` (
- `id_categoria` INT(3) NOT NULL,
- `nombre` VARCHAR(50) DEFAULT NULL,
- PRIMARY KEY (`id_categoria`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- -- ----------------------------
- -- Records of categoria
- -- ----------------------------
- INSERT INTO `categoria` VALUES ('1', 'indefinido');
- INSERT INTO `categoria` VALUES ('2', 'a plazo');
- -- ----------------------------
- -- Table structure for contratos
- -- ----------------------------
- DROP TABLE IF EXISTS `contratos`;
- CREATE TABLE `contratos` (
- `nro_contrato` INT(3) NOT NULL,
- `dni` INT(3) NOT NULL,
- `id_categoria` INT(3) NOT NULL,
- `fecha_inicial` DATE DEFAULT NULL,
- `fecha_final` DATE DEFAULT NULL,
- PRIMARY KEY (`nro_contrato`),
- KEY `dni` (`dni`),
- KEY `id_categoria` (`id_categoria`),
- CONSTRAINT `contratos_ibfk_1` FOREIGN KEY (`dni`) REFERENCES `trabajadores` (`dni`),
- CONSTRAINT `contratos_ibfk_2` FOREIGN KEY (`id_categoria`) REFERENCES `categoria` (`id_categoria`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- -- ----------------------------
- -- Records of contratos
- -- ----------------------------
- INSERT INTO `contratos` VALUES ('1', '3', '1', '2014-08-01', '2014-10-30');
- INSERT INTO `contratos` VALUES ('2', '2', '2', '2014-01-01', '2014-06-01');
- INSERT INTO `contratos` VALUES ('3', '5', '2', '2014-02-15', '2014-08-15');
- INSERT INTO `contratos` VALUES ('4', '2', '1', NULL, NULL);
- INSERT INTO `contratos` VALUES ('5', '2', '1', NULL, NULL);
- INSERT INTO `contratos` VALUES ('6', '2', '1', NULL, NULL);
- -- ----------------------------
- -- Table structure for departamento
- -- ----------------------------
- DROP TABLE IF EXISTS `departamento`;
- CREATE TABLE `departamento` (
- `cod_departamento` INT(3) NOT NULL,
- `nombre` VARCHAR(50) DEFAULT NULL,
- `dni_coordinador` INT(3) DEFAULT NULL,
- PRIMARY KEY (`cod_departamento`),
- KEY `dni_coordinador` (`dni_coordinador`),
- CONSTRAINT `departamento_ibfk_1` FOREIGN KEY (`dni_coordinador`) REFERENCES `trabajadores` (`dni`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- -- ----------------------------
- -- Records of departamento
- -- ----------------------------
- INSERT INTO `departamento` VALUES ('1', 'administracion', '1');
- INSERT INTO `departamento` VALUES ('2', 'finanzas', '2');
- INSERT INTO `departamento` VALUES ('3', 'informatica', '3');
- -- ----------------------------
- -- Table structure for nominas
- -- ----------------------------
- DROP TABLE IF EXISTS `nominas`;
- CREATE TABLE `nominas` (
- `id_nomina` INT(3) NOT NULL DEFAULT '0',
- `nro_contrato` INT(3) DEFAULT NULL,
- `fecha` DATE DEFAULT NULL,
- `salario` INT(6) DEFAULT NULL,
- PRIMARY KEY (`id_nomina`),
- KEY `nro_contrato` (`nro_contrato`),
- CONSTRAINT `nominas_ibfk_1` FOREIGN KEY (`nro_contrato`) REFERENCES `contratos` (`nro_contrato`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- -- ----------------------------
- -- Records of nominas
- -- ----------------------------
- INSERT INTO `nominas` VALUES ('1', '1', '2014-09-30', '200000');
- INSERT INTO `nominas` VALUES ('2', '1', '2014-09-30', '250000');
- INSERT INTO `nominas` VALUES ('3', '3', '2014-08-15', '800000');
- -- ----------------------------
- -- Table structure for responsable_nomina
- -- ----------------------------
- DROP TABLE IF EXISTS `responsable_nomina`;
- CREATE TABLE `responsable_nomina` (
- `id_nomina` INT(3) NOT NULL DEFAULT '0',
- `nro_contrato` INT(3) NOT NULL DEFAULT '0',
- `dni_responsable_nomina` INT(3) NOT NULL DEFAULT '0',
- PRIMARY KEY (`id_nomina`,`nro_contrato`,`dni_responsable_nomina`),
- KEY `nro_contrato` (`nro_contrato`),
- KEY `dni_responsable_nomina` (`dni_responsable_nomina`),
- CONSTRAINT `responsable_nomina_ibfk_1` FOREIGN KEY (`id_nomina`) REFERENCES `nominas` (`id_nomina`),
- CONSTRAINT `responsable_nomina_ibfk_2` FOREIGN KEY (`nro_contrato`) REFERENCES `contratos` (`nro_contrato`),
- CONSTRAINT `responsable_nomina_ibfk_3` FOREIGN KEY (`dni_responsable_nomina`) REFERENCES `trabajadores` (`dni`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- -- ----------------------------
- -- Records of responsable_nomina
- -- ----------------------------
- INSERT INTO `responsable_nomina` VALUES ('1', '1', '1');
- INSERT INTO `responsable_nomina` VALUES ('2', '2', '1');
- INSERT INTO `responsable_nomina` VALUES ('3', '3', '1');
- -- ----------------------------
- -- Table structure for trabajadores
- -- ----------------------------
- DROP TABLE IF EXISTS `trabajadores`;
- CREATE TABLE `trabajadores` (
- `dni` INT(3) NOT NULL,
- `nombre` VARCHAR(50) DEFAULT NULL,
- `apellidos` VARCHAR(50) DEFAULT NULL,
- `telefono` INT(10) DEFAULT NULL,
- `direccion` VARCHAR(50) DEFAULT NULL,
- `comuna` VARCHAR(50) DEFAULT NULL,
- `dni_jefe` INT(3) DEFAULT NULL,
- `cod_departamento` INT(3) NOT NULL,
- PRIMARY KEY (`dni`),
- KEY `dni_jefe` (`dni_jefe`),
- KEY `cod_departamento` (`cod_departamento`),
- CONSTRAINT `trabajadores_ibfk_1` FOREIGN KEY (`dni_jefe`) REFERENCES `trabajadores` (`dni`),
- CONSTRAINT `trabajadores_ibfk_2` FOREIGN KEY (`cod_departamento`) REFERENCES `departamento` (`cod_departamento`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- -- ----------------------------
- -- Records of trabajadores
- -- ----------------------------
- INSERT INTO `trabajadores` VALUES ('1', 'juan', 'molina', '12345', 'calle siempre viva', 'springfield', '4', '1');
- INSERT INTO `trabajadores` VALUES ('2', 'lalo', 'landa', '92374', 'los carrera 34', 'concepcion', '4', '2');
- INSERT INTO `trabajadores` VALUES ('3', 'suricate', 'africano', '99999', 'en la llanura africana', 'congo', '4', '3');
- INSERT INTO `trabajadores` VALUES ('4', 'pepe', 'vidal', '435657', 'basilon 123', 'concepcion', NULL, '1');
- INSERT INTO `trabajadores` VALUES ('5', 'alan', 'brito', '12345', 'arturo prat', 'chillan', '4', '2');
- -- ----------------------------
- -- View structure for trabajadores_conce
- -- ----------------------------
- DROP VIEW IF EXISTS `trabajadores_conce`;
- 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