I downloaded a few databases from Census - Fact Finder:
And started working with California Housing Database, using CVed I took out all the columns that I didn´t need and then proceed to create a Model in MySQL Workbench which I later turn into a DB via command lines:
-- 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 Census
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema Census
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `Census` DEFAULT CHARACTER SET utf8 ;
USE `Census` ;
-- -----------------------------------------------------
-- Table `Census`.`Housing`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Census`.`Housing` (
`SERIALNO` BIGINT(13) NOT NULL,
`DIVISION` INT(9) NULL,
`PUMA` INT(4) NULL,
`REGION` INT(1) NULL,
`ST` INT(1) NULL,
`ADJHSG` INT(7) NULL,
`ADJINC` INT(7) NULL,
`FINCP` INT(6) NULL,
`HINCP` INT(6) NULL,
`R60` INT(1) NULL,
`R65` INT(1) NULL,
PRIMARY KEY (`SERIALNO`))
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
After the DB was created I proceeded to import the data:
LOAD DATA INFILE "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/Housing_California.csv"
INTO TABLE housing
CHARACTER SET latin1
COLUMNS TERMINATED BY ','
LINES TERMINATED BY '\n';
But it doesn´t work as this error message appears:
ERROR 1366 (HY000): Incorrect integer value: '' for column 'FINCP' at row 15
Now, I now that at that row my I have a blank value, that column refers to the Family Income which in some cases was 0 so Census left it as blank:
2012000000135,9,6515,4,6,1045360,1056030,,43100,1,0
I could change all the blank cells to 0 but I feel like there has to be a better way to handle things.
Hope you can give me a tip.