View Single Post

   
  #2 (permalink)  
Old 02-28-2008, 11:29 AM
Paul Lautman
 
Posts: n/a
Default Re: how to add a primary key to a table

anne001 wrote:
> show columns from score, where student_id is a foreign key to one
> table, and event_id a foreign key to another.
>
> +------------+------------------+------+-----+---------+-------+
>> Field | Type | Null | Key | Default |

> Extra |
> +------------+------------------+------+-----+---------+-------+
>> student_id | int(10) unsigned | NO | PRI | |
>>
>> event_id | int(10) unsigned | NO | PRI | |
>>
>> score | int(11) | NO | | |
>>

> +------------+------------------+------+-----+---------+-------+
>
>
> this blog gives the recipee, but it does not work for me
> http://www.jroller.com/dschneller/en...primary_key_to
>
> mysql> ALTER TABLE child
> -> ADD COLUMN child_id BIGINT(20) AUTO_INCREMENT NOT
> NULL FIRST,
> -> ADD PRIMARY KEY(child_id);
>
> alter table score
> -> add column id bigint(2) auto_increment not null
> first,
> -> add primary key(id);
> ERROR 1068 (42000): Multiple primary key defined
>
> what do I need to do to add a primary key to this table?


The table already has a primary key. A table can have only one primary key.


Reply With Quote