0

I'm trying to create a table to capture details of subtype variations using auto_increment but I keep get an error saying:

1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

However, I'm unsure how to capture it all correctly as I want the auto_increment of subtypes to start from 1 for each TypeId....is this not possible?

CREATE TABLE IF NOT EXISTS `types` (
  `TypeID` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `TypeFeatures` TEXT NOT NULL,
  PRIMARY KEY (`TypeID`))
ENGINE = InnoDB;


insert into types 
    (TypeFeatures)
values
    (1,'Type1'),
    (2,'Type2'),
    (3,'Type3')
;

  
CREATE TABLE IF NOT EXISTS `subtypes` (
  `Type_ID` INT UNSIGNED NOT NULL,
  `SubtypeID` TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `SubtypeFeatures` TEXT NOT NULL,
  PRIMARY KEY(`Type_ID`,`SubtypeID`))
ENGINE = InnoDB;

insert into subtypes 
    (Type_ID,subtypeID,SubtypeFeatures)
values
    (1,1,'Subtype1'),
    (1,2,'Subtype2'),
    (2,1,'Subtype1'),
    (3,1,'Subtype1')
;

Thanks in advance for any suggestions! Bendy

Community
  • 1
  • 1
Bendy
  • 3,506
  • 6
  • 40
  • 71

0 Answers0