Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Chaves estrangeiras do MySQL em si mesmo


Altere o tipo da coluna idParent para int(10) unsigned . Portanto, é do mesmo tipo que a coluna referenciada idBC .
DROP TABLE IF EXISTS `biological classification`;
CREATE TABLE `biological classification` (
  `idBC` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `idParent` int(10) unsigned DEFAULT NULL,
  `type` varchar(45) DEFAULT NULL,
  `value` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`idBC`),
  UNIQUE KEY `idnew_table_UNIQUE` (`idBC`),
  CONSTRAINT `SelfKey` FOREIGN KEY (`idParent`) REFERENCES `biological classification` (`idBC`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1 COMMENT='A table that contains the Biological Classification of anima';