merrill
merrill

Reputation: 591

mysql how do I change the column id from varchars to ints and autoincreasing?

How do I make the change of the column ID in the table to ints and auto-increment through phpmyadmin?

Thanks

Upvotes: 0

Views: 115

Answers (3)

Devart
Devart

Reputation: 121902

If there is no primary key, try this statement -

ALTER TABLE table
  CHANGE COLUMN id id INT(11) NOT NULL AUTO_INCREMENT,
  ADD PRIMARY KEY (id);

Otherwise, you can run a script like this -

ALTER TABLE table
  CHANGE COLUMN id id INT(11) NOT NULL AUTO_INCREMENT;

Upvotes: 1

Akhil Thayyil
Akhil Thayyil

Reputation: 9403

Do the following steps :

1) Make the datatype of columns for autoincrement as BIGINT 2) Make the same column as primary key. 3) Then add the auto inrement option as shown in the image AUTO INCREMENT

Upvotes: 0

Marco
Marco

Reputation: 57573

Try this:

ALTER TABLE your_table
CHANGE ID ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY

Upvotes: 1

Related Questions