-- MySQL Script generated by MySQL Workbench
-- lun 20 feb 2017 12:41:40 CET
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

-- -----------------------------------------------------
-- Schema Componentes
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `Componentes` ;

-- -----------------------------------------------------
-- Schema Componentes
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `Componentes` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `Componentes` ;

-- -----------------------------------------------------
-- Table `Componentes`.`PROVEEDORES`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Componentes`.`PROVEEDORES` ;

CREATE TABLE IF NOT EXISTS `Componentes`.`PROVEEDORES` (
  `IDP` VARCHAR(4) NOT NULL COMMENT '',
  `PNOMBRE` VARCHAR(20) NULL COMMENT '',
  `CATEGORIA` INT NULL COMMENT '',
  `CIUDAD` VARCHAR(20) NULL COMMENT '',
  PRIMARY KEY (`IDP`)  COMMENT '')
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Componentes`.`COMPONENTES`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Componentes`.`COMPONENTES` ;

CREATE TABLE IF NOT EXISTS `Componentes`.`COMPONENTES` (
  `IDC` VARCHAR(4) NOT NULL COMMENT '',
  `CNOMBRE` VARCHAR(20) NULL COMMENT '',
  `COLOR` VARCHAR(20) NULL COMMENT '',
  `PESO` INT NULL COMMENT '',
  `CIUDAD` VARCHAR(20) NULL COMMENT '',
  PRIMARY KEY (`IDC`)  COMMENT '')
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Componentes`.`ARTICULOS`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Componentes`.`ARTICULOS` ;

CREATE TABLE IF NOT EXISTS `Componentes`.`ARTICULOS` (
  `IDT` VARCHAR(4) NOT NULL COMMENT '',
  `TNOMBRE` VARCHAR(20) NULL COMMENT '',
  `CIUDAD` VARCHAR(20) NULL COMMENT '',
  PRIMARY KEY (`IDT`)  COMMENT '')
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Componentes`.`ENVIOS`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `Componentes`.`ENVIOS` ;

CREATE TABLE IF NOT EXISTS `Componentes`.`ENVIOS` (
  `IDP` VARCHAR(4) NOT NULL COMMENT '',
  `IDT` VARCHAR(4) NOT NULL COMMENT '',
  `IDC` VARCHAR(4) NOT NULL COMMENT '',
  `CANT` INT NULL COMMENT '',
  PRIMARY KEY (`IDC`, `IDP`, `IDT`)  COMMENT '',
  CONSTRAINT `fk_ENVIOS_PROVEEDORES1`
    FOREIGN KEY (`IDP`)
    REFERENCES `Componentes`.`PROVEEDORES` (`IDP`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_ENVIOS_ARTICULOS1`
    FOREIGN KEY (`IDT`)
    REFERENCES `Componentes`.`ARTICULOS` (`IDT`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_ENVIOS_COMPONENTES1`
    FOREIGN KEY (`IDC`)
    REFERENCES `Componentes`.`COMPONENTES` (`IDC`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_ENVIOS_PROVEEDORES1_idx` ON `Componentes`.`ENVIOS` (`IDP` ASC)  COMMENT '';

CREATE INDEX `fk_ENVIOS_ARTICULOS1_idx` ON `Componentes`.`ENVIOS` (`IDT` ASC)  COMMENT '';


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

-- -----------------------------------------------------
-- Data for table `Componentes`.`PROVEEDORES`
-- -----------------------------------------------------
START TRANSACTION;
USE `Componentes`;
INSERT INTO `Componentes`.`PROVEEDORES` (`IDP`, `PNOMBRE`, `CATEGORIA`, `CIUDAD`) VALUES ('P1', 'CARLOS',  20, 'SEVILLA  ');
INSERT INTO `Componentes`.`PROVEEDORES` (`IDP`, `PNOMBRE`, `CATEGORIA`, `CIUDAD`) VALUES ('P2', 'JUAN',    10, 'MADRID   ');
INSERT INTO `Componentes`.`PROVEEDORES` (`IDP`, `PNOMBRE`, `CATEGORIA`, `CIUDAD`) VALUES ('P3', 'JOSE',    30, 'SEVILLA  ');
INSERT INTO `Componentes`.`PROVEEDORES` (`IDP`, `PNOMBRE`, `CATEGORIA`, `CIUDAD`) VALUES ('P4', 'INMA',    20, 'SEVILLA  ');
INSERT INTO `Componentes`.`PROVEEDORES` (`IDP`, `PNOMBRE`, `CATEGORIA`, `CIUDAD`) VALUES ('P5', 'EVA',     30, 'CACERES  ');

COMMIT;


-- -----------------------------------------------------
-- Data for table `Componentes`.`COMPONENTES`
-- -----------------------------------------------------
START TRANSACTION;
USE `Componentes`;
INSERT INTO `Componentes`.`COMPONENTES` (`IDC`, `CNOMBRE`, `COLOR`, `PESO`, `CIUDAD`) VALUES ('C1', 'X3A', 'ROJO ',  12, 'SEVILLA');
INSERT INTO `Componentes`.`COMPONENTES` (`IDC`, `CNOMBRE`, `COLOR`, `PESO`, `CIUDAD`) VALUES ('C2', 'B85', 'VERDE',  17, 'MADRID ');
INSERT INTO `Componentes`.`COMPONENTES` (`IDC`, `CNOMBRE`, `COLOR`, `PESO`, `CIUDAD`) VALUES ('C3', 'C4B', 'AZUL ',  17, 'MALAGA ');
INSERT INTO `Componentes`.`COMPONENTES` (`IDC`, `CNOMBRE`, `COLOR`, `PESO`, `CIUDAD`) VALUES ('C4', 'C4B', 'ROJO ',  14, 'SEVILLA ');
INSERT INTO `Componentes`.`COMPONENTES` (`IDC`, `CNOMBRE`, `COLOR`, `PESO`, `CIUDAD`) VALUES ('C5', 'VT8', 'AZUL ',  12, 'MADRID ');
INSERT INTO `Componentes`.`COMPONENTES` (`IDC`, `CNOMBRE`, `COLOR`, `PESO`, `CIUDAD`) VALUES ('C6', 'C30', 'ROJO ',  19, 'SEVILLA');

COMMIT;


-- -----------------------------------------------------
-- Data for table `Componentes`.`ARTICULOS`
-- -----------------------------------------------------
START TRANSACTION;
USE `Componentes`;
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T1', 'CLASIFICADORA', 'MADRID ');
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T2', 'PERFORADORA', 'MALAGA ');
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T3', 'LECTORA', 'CACERES ');
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T4', 'CONSOLA', 'CACERES ');
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T5', 'MEZCLADORA', 'SEVILLA  ');
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T6', 'TERMINAL', 'BARCELONA ');
INSERT INTO `Componentes`.`ARTICULOS` (`IDT`, `TNOMBRE`, `CIUDAD`) VALUES ('T7', 'CINTA', 'SEVILLA ');

COMMIT;


-- -----------------------------------------------------
-- Data for table `Componentes`.`ENVIOS`
-- -----------------------------------------------------
START TRANSACTION;
USE `Componentes`;
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P1', 'T1', 'C1',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P1', 'T4', 'C1',  700 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T1', 'C3',  400 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T2', 'C3',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T3', 'C3',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T4', 'C3',  500 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T5', 'C3',  600 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T6', 'C3',  400 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T7', 'C3',  800 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P2', 'T2', 'C5',  100 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P3', 'T1', 'C3',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P3', 'T2', 'C4',  500 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P4', 'T3', 'C6',  300 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P4', 'T7', 'C6',  300 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T2', 'C2',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T4', 'C2',  100 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T4', 'C5',  500 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T7', 'C5',  100 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T2', 'C6',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T4', 'C1',  100 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T4', 'C3',  200 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T4', 'C4',  800 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T5', 'C5',  400 );
INSERT INTO `Componentes`.`ENVIOS` (`IDP`, `IDT`, `IDC`, `CANT`) VALUES ('P5', 'T4', 'C6',  500 );

COMMIT;

