Solved

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

Posted on 2009-05-04
2
3,234 Views
Last Modified: 2012-05-06
I am attempting to migrate from MS SQL to MYSQL, using the MYSQL Migration Toolkit.  I have generated scripts with the tool that I am running from myPHPadmin.  While some of the CREATE TABLE commands are working, a few of them generate this error:

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

My understanding is you cannot have more than one field with auto_increment, and it must be primary key.  Can you not have multiple primary keys but set only one of the to auto_increment?


DROP TABLE IF EXISTS `captain1`.`tblEducation`;
CREATE TABLE `captain1`.`tblEducation` (
  `UserID` INT(10) NOT NULL,
  `EducationID` INT(10) NOT NULL AUTO_INCREMENT,
  `InstituteName` VARCHAR(50) NULL,
  `ProgramName` VARCHAR(50) NULL,
  `LevelObtained` VARCHAR(50) NULL,
  `StudyFrom` DATETIME NULL,
  `StudyTo` DATETIME NULL,
  `GradDate` DATETIME NULL,
  `Skills` VARCHAR(50) NULL,
  `Type` VARCHAR(50) NULL,
  PRIMARY KEY (`UserID`, `EducationID`),
  CONSTRAINT `FK_tblEducation_tblUsers` FOREIGN KEY `FK_tblEducation_tblUsers` (`UserID`)
    REFERENCES `captain1`.`tblUsers` (`UserID`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION
)
ENGINE = INNODB;

Open in new window

0
Comment
Question by:phisherpryce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Assisted Solution

by:gamebits
gamebits earned 200 total points
ID: 24298088
A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. If you do not have a PRIMARY KEY and an application asks for the PRIMARY KEY in your tables, MySQL returns the first UNIQUE index that has no NULL columns as the PRIMARY KEY.

More info here

http://dev.mysql.com/doc/refman/5.1/en/create-table.html
0
 
LVL 17

Accepted Solution

by:
k_murli_krishna earned 300 total points
ID: 24298093
Please refer:
http://www.experts-exchange.com/Database/MySQL/Q_24265504.html

You have to make UserID also as an AUTO_INCREMENT column and have the rest definition as it is and the table should get created.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question