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'; CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ; USE `mydb`; CREATE TABLE IF NOT EXISTS `mydb`.`table1` ( `idtable1` INT(11) NOT NULL , `fk_test` INT(11) NOT NULL , PRIMARY KEY (`idtable1`) , INDEX `fk_test` (`fk_test` ASC) , CONSTRAINT `fk_test` FOREIGN KEY (`fk_test` ) REFERENCES `mydb`.`table3` (`idtable3` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1 COLLATE = latin1_swedish_ci; CREATE TABLE IF NOT EXISTS `mydb`.`table2` ( `idtable2` INT(11) NOT NULL , `fk_test` INT(11) NOT NULL , PRIMARY KEY (`idtable2`) , INDEX `fk_test` (`fk_test` ASC) , CONSTRAINT `fk_test` FOREIGN KEY (`fk_test` ) REFERENCES `mydb`.`table3` (`idtable3` ) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1 COLLATE = latin1_swedish_ci; CREATE TABLE IF NOT EXISTS `mydb`.`table3` ( `idtable3` INT(11) NOT NULL , PRIMARY KEY (`idtable3`) ) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1 COLLATE = latin1_swedish_ci; SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;