PHP Classes

Multiple Primary keys error

Recommend this page to a friend!

      MySQL backup class  >  All threads  >  Multiple Primary keys error  >  (Un) Subscribe thread alerts  
Subject:Multiple Primary keys error
Summary:Script creates wrong sintax for table with multiple PK
Messages:5
Author:leo
Date:2005-07-12 16:52:49
Update:2005-07-12 21:27:09
 

  1. Multiple Primary keys error   Reply   Report abuse  
Picture of leo leo - 2005-07-12 16:52:49
In case you have a simple table with multiple Primary Keys eg:

CREATE TABLE `item_subitem` (
`itemid` int(5) unsigned NOT NULL default '0',
`subitemid` int(5) unsigned NOT NULL default '0',
PRIMARY KEY (`itemid`,`subitemid`)
) TYPE=MyISAM


The script will generate the following:

create table item_subitem
(
itemid int unsigned primary key,
subitemid int unsigned primary key
);

And this will throw an error while trying to execute:

ERROR 1068 (42000) at line 256: Multiple primary key defined

Is there any maintenance of this script?

  2. Re: Multiple Primary keys error   Reply   Report abuse  
Picture of Can Ince Can Ince - 2005-07-12 19:39:28 - In reply to message 1 from leo
Only one primary key may be defined for the same table.
So, it's not a bug.

  3. Re: Multiple Primary keys error   Reply   Report abuse  
Picture of leo leo - 2005-07-12 20:19:42 - In reply to message 2 from Can Ince
Im afraid not. You may have a goup of fields, assigned as a primary key, in the same table.
They would be foreign keys, also

  4. Re: Multiple Primary keys error   Reply   Report abuse  
Picture of leo leo - 2005-07-12 20:22:11 - In reply to message 2 from Can Ince
By the way.. if you run this:
CREATE TABLE `item_subitem` (
`itemid` int(5) unsigned NOT NULL default '0',
`subitemid` int(5) unsigned NOT NULL default '0',
PRIMARY KEY (`itemid`,`subitemid`)
) TYPE=MyISAM

you will fin that it's a perfectly valid statement.

Actually, the example above, is a table definition in an existing database. And the code below, was generated by this script.

  5. Re: Multiple Primary keys error   Reply   Report abuse  
Picture of Can Ince Can Ince - 2005-07-12 21:27:09 - In reply to message 4 from leo
Well, it's still only one primary key.. However, I apologize as I misunderstood the question. Probably, a case where multiple coloumns will be added to the primary key, is forgotten.
Let me -and the author of course!- check the code against it.