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';

DROP SCHEMA IF EXISTS `ranchdb` ;
CREATE SCHEMA IF NOT EXISTS `ranchdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `ranchdb` ;

-- -----------------------------------------------------
-- Table `ranchdb`.`cordinate_points`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ranchdb`.`cordinate_points` ;

CREATE  TABLE IF NOT EXISTS `ranchdb`.`cordinate_points` (
  `idcordinate` INT NOT NULL ,
  `cowid` INT NOT NULL ,
  `date` DATE NOT NULL ,
  `Y` DOUBLE NOT NULL ,
  `X` DOUBLE NOT NULL ,
  PRIMARY KEY (`idcordinate`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ranchdb`.`pixel`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ranchdb`.`pixel` ;

CREATE  TABLE IF NOT EXISTS `ranchdb`.`pixel` (
  `idpixel` INT NOT NULL ,
  `X` DOUBLE NOT NULL ,
  `Y` DOUBLE NOT NULL ,
  PRIMARY KEY (`idpixel`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `ranchdb`.`speed_pixel`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `ranchdb`.`speed_pixel` ;

CREATE  TABLE IF NOT EXISTS `ranchdb`.`speed_pixel` (
  `cordinate_points_idcordinate` INT NOT NULL ,
  `pixel_idpixel` INT NOT NULL ,
  `distance` DOUBLE NOT NULL ,
  PRIMARY KEY (`cordinate_points_idcordinate`) ,
  INDEX `fk_speed_pixel_pixel1_idx` (`pixel_idpixel` ASC) ,
  CONSTRAINT `fk_speed_pixel_cordinate_points1`
    FOREIGN KEY (`cordinate_points_idcordinate` )
    REFERENCES `ranchdb`.`cordinate_points` (`idcordinate` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_speed_pixel_pixel1`
    FOREIGN KEY (`pixel_idpixel` )
    REFERENCES `ranchdb`.`pixel` (`idpixel` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

USE `ranchdb` ;


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