List:General Discussion« Previous MessageNext Message »
From:Randy Paries Date:November 2 2006 2:23am
Subject:help trying to add an autoincrement col to an exisiting table
View as plain text  
Hello,
currently i have the following table structure

CREATE TABLE users (
  uname varchar(20) NOT NULL default '',
  passwd varchar(15) NOT NULL default '',
  fname varchar(25) NOT NULL default '',
  lname varchar(40) NOT NULL default '',
  dir varchar(28) NOT NULL default '',
  pict varchar(50) NOT NULL default '',
  level int(4) NOT NULL default '0',
  email varchar(40) NOT NULL default '',
  rank int(4) NOT NULL default '0',
  dgroup int(4) NOT NULL default '0',
  parent varchar(20) NOT NULL default '',
  seminar int(11) NOT NULL default '0',
  getnewsletter int(11) default '0',
  PRIMARY KEY  (uname),
  KEY uname_users (uname),
  KEY dir_users (dir),
  KEY seminar_users (seminar),
  KEY user_lvl_idx (level)
) TYPE=MyISAM;

I want to add an autoincrement field

when i first tried i got the error

Incorrect table definition; there can be only one auto column and it
must be defined as a key

so then i tried
ALTER TABLE `users` DROP PRIMARY KEY;
ALTER TABLE `users` ADD PRIMARY KEY (id);
ALTER TABLE `users` CHANGE `id` `keyid` INT(10)  UNSIGNED NOT NULL
AUTO_INCREMENT;

and i get the error
Duplicate entry '0' for key 1

Can some one please tell me what i am doing wrong
Thanks
Thread
help trying to add an autoincrement col to an exisiting tableRandy Paries2 Nov
  • Re: help trying to add an autoincrement col to an exisiting tableRolando Edwards2 Nov