List:MySQL on Win32« Previous MessageNext Message »
From:Christian Mack Date:May 18 1999 3:57pm
Subject:Re: Adding a new primary key field
View as plain text  
Bob Stickel wrote:
> 
> I have a database (aerial) and two tables (flights982 and master982) running
> under mysql Win32 and myodbc. Neither of these tables has a primary key
> field. I would like to alter the tables to make a field name "id" as the
> primary key with auto_increment enabled. here is what I tried:
> 
> mysql> use aerial
> database changed
> 
> mysql> alter table flights982,
>     -> insert into table flights982,
>     -> id tinyint(4) DEFAULT '0' NOT NULL auto_increment,
>     -> PRIMARY KEY (id);
> 
> I get a parse error for line 2  so my syntax must be wrong but I can't
> figure what I'm doing wrong. I didn't know whether or not to drop the data
> from the table to do this operation...
> 
> Thanks
> 
> Bob

Hi Bob

There is no 'INSERT INTO' allowed in the ALTER TABLE syntax.
What you search for is:
ALTER TABLE 
	flights982
ADD
	id TINYINT NOT NULL AUTO_INCREMENT PRIMARY KEY

Tschau
Christian

Thread
Adding a new primary key fieldBob Stickel18 May
  • Re: Adding a new primary key fieldChristian Mack18 May