matthew016
asked on
Can't alter a table
Hi,
I added a field called "id" to a table,
now I have the following error :
MySQL Error Number 1063
Incorrect Column specifier for column 'id'
I added a field id NUMERIC(5) as primary key
what's wrong ?
Also, what type is suggested for a id as primary key ?
Thank u .
I added a field called "id" to a table,
now I have the following error :
MySQL Error Number 1063
Incorrect Column specifier for column 'id'
I added a field id NUMERIC(5) as primary key
what's wrong ?
Also, what type is suggested for a id as primary key ?
Thank u .
... and if you want to add primary key through ALTER TABLE, you must use auto_increment
ALTER TABLE mytable ADD column id (int not null auto_increment primary key)
ALTER TABLE mytable ADD column id (int not null auto_increment primary key)
ASKER
not null is checked ... I'm using mysql administrator
if your table contents data, you cannot add primary key without data... auto_increment create unique values.
can you sen your ALTER TABLE statement?
can you sen your ALTER TABLE statement?
ASKER
There is no data in the table,
ALTER TABLE `le_hall`.`utilisateurs` ADD COLUMN `id` NUMERIC(5) NOT NULL AUTO_INCREMENT AFTER `description`,
DROP PRIMARY KEY,
ADD PRIMARY KEY(`id`);
ALTER TABLE `le_hall`.`utilisateurs` ADD COLUMN `id` NUMERIC(5) NOT NULL AUTO_INCREMENT AFTER `description`,
DROP PRIMARY KEY,
ADD PRIMARY KEY(`id`);
alter table ax drop column old_pk_column;
alter table `le_hall`.`utilisateurs` add column (id NUMERIC(5) not null auto_increment primary key AFTER `description`)
alter table `le_hall`.`utilisateurs` add column (id NUMERIC(5) not null auto_increment primary key AFTER `description`)
ASKER
alter table ax ?
what is ax ?
what is ax ?
sorry
alter table `le_hall`.`utilisateurs` drop column old_pk_column;
alter table `le_hall`.`utilisateurs` add column (id NUMERIC(5) not null auto_increment primary key AFTER `description`)
alter table `le_hall`.`utilisateurs` drop column old_pk_column;
alter table `le_hall`.`utilisateurs` add column (id NUMERIC(5) not null auto_increment primary key AFTER `description`)
ASKER
I have no idea on how to execute sql code in mysql administrator,
but I removed the PK then saved,
then I try to add the new PK id and I have still the error
but I removed the PK then saved,
then I try to add the new PK id and I have still the error
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
well with INTEGER type it works,
but i always used NUMERIC(5)
Whats wrong with it ?
but i always used NUMERIC(5)
Whats wrong with it ?
I¨v got it - one more step
alter table `le_hall`.`utilisateurs` drop column old_pk_column;
alter table `le_hall`.`utilisateurs` add column (id int not null auto_increment primary key)
alter table `le_hall`.`utilisateurs` MODIFY id NUM(5)?
alter table `le_hall`.`utilisateurs` drop column old_pk_column;
alter table `le_hall`.`utilisateurs` add column (id int not null auto_increment primary key)
alter table `le_hall`.`utilisateurs` MODIFY id NUM(5)?
sorry ; not ? at end
alter table `le_hall`.`utilisateurs` MODIFY id NUM(5);
alter table `le_hall`.`utilisateurs` MODIFY id NUM(5);
ASKER
hmmm weird, i'll leave it as int
thanks.
thanks.
CREATE TABLE xxx (id int not null primary key, nex_col int, next_col2 varchar(225))