List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 26 2002 12:56am
Subject:Re: primary keys
View as plain text  
At 11:55 -0700 9/23/02, johnbarri wrote:
>Hi - I'm a mysql newbie.  As I've yet to discover a method of batching mysql
>commands I prefer to input lengthy instructions (such as large file
>structures) in stages, so input errors can be dealt with more easily.  For
>example, I first define table structures and then indexes.
>This led me to use "create index" for the latter.  The following syntax
>"create index city_idx on city_country_masterfile (city);"  worked  for an
>ordinary index definition.
>However, when  I wanted to define the fourth column (pkey) as a primary key
>I could not get create index to work - I misunderstood the syntax or was
>misapplying "create index".

CREATE INDEX cannot create a PRIMARY KEY.  It has no syntax for it.
DROP INDEX won't drop a PRIMARY KEY, either.

>What finally worked for me was "alter table city_country_masterfile add
>primary key (pkey);".

That's what you need to do.
primary keysjohnbarri26 Sep
  • Re: primary keysPaul DuBois26 Sep