Double primary key in MySQL

Posted by ads' corner on Thursday, 2007-08-02
Posted in [Other-Dbs]

Got a nice MySQL problem: a table, which has the following primary key: id, id.

You can use, or dump, this table without problems … but you cannot reinsert the dump into the same (4.1) or a newer (5.0) MySQL version.

This is the table dump, created with SHOW CREATE TABLE tablename:

1
2
3
4
5
6
CREATE TABLE tablename (
  id int(11) NOT NULL auto_increment,
  title_en text,
  ...
  PRIMARY KEY  (id,id)
) TYPE=MyISAM DEFAULT CHARSET=latin1;

Now I try to reinsert this table into another database:

1
2
3
4
5
6
7
mysql> CREATE TABLE tablename (
    ->   id int(11) NOT NULL auto_increment,
    ->   title_en text,
  ...
    ->   PRIMARY KEY  (id,id)
    -> ) TYPE=MyISAM DEFAULT CHARSET=latin1;
ERROR 1060 (42S21): Duplicate column name 'id'

What the …

Shall I repeat myself?


Categories: [Other-Dbs]
Tags: [Mysql] [Primary-Key]