12

I've been trying to add auto-increment to one of my columns (basically an ID) but I can't find the auto-increment option for my column. Any idea where it is?

SKLAK
  • 3,825
  • 9
  • 33
  • 57

6 Answers6

23

To use the GUI:

Click the STRUCTURE tab to see the list of existing fields

To set a field as the PRIMARY FIELD, click the gold key -- it will turn silver.

To set a field (usually the same field) as auto-increment:
a. Click CHANGE for that field
b. Look to the far right and checkmark the AI box
c. Click SAVE button

cssyphus
  • 37,875
  • 18
  • 96
  • 111
22

You can add it like this

ALTER TABLE your_table
MODIFY some_column INT NOT NULL AUTO_INCREMENT;
juergen d
  • 201,996
  • 37
  • 293
  • 362
5

A couple quick points based on recent experience:

  1. To the original question, how to select auto-increment with phpmyadmin, it's the small AI check box on the change screen for a field name.

  2. When I tried the "ALTER TABLE tablew_name CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT;" solution above, phpmyadmin gave me an error message saying the field had to have a key. I selected a Unique key and the error message went away and the field now auto increments.

FredHead
  • 218
  • 2
  • 7
  • Your answer is incorrect, and as much as you want to help - it's misleading. Only a primary key can be auto_increment, and primary key is unique - therefore your point number 2. is inaccurate. I won't downvote but could you adjust your answer so it's closer to accurate? – N.B. Sep 15 '15 at 16:58
  • As noted in my edit, my answer was correct, as far as I can tell, in that selecting a Unique key in phpmyadmin removed an error message that prevented using one of the solutions above. I was not commenting on the relative merits of unique keys vs primary keys or any similarities/differences/relationships between them, only pointing out my experience as noted in my original answer, an experience that may or may not be useful to the next person Googling for ideas on how to do this with phpmyadmin. – FredHead Sep 16 '15 at 00:00
  • Alright, your edited answer makes more sense now, up you go. – N.B. Sep 16 '15 at 16:35
4

This wont work if there are any foreign keys defined, and that is very likely for id fields.

use:

ALTER TABLE tablew_name CHANGE id id BIGINT(20) NOT NULL AUTO_INCREMENT;

instead

Oliver
  • 117
  • 1
  • 5
0

The SQL script is correct

ALTER TABLE your_table MODIFY some_column INT NOT NULL AUTO_INCREMENT;

but if you try so make before in the visual mode, with the mysql version 4.7.4, in the struct of the table

Appear when you create the table one option to say "A_I" , if you put your mouse appear message with AUTO_INCREMENT (The version of the foto is in Spanish version)

roschach
  • 8,390
  • 14
  • 74
  • 124
Miguel_J
  • 43
  • 6
0

If you are using xampp:

step 1: Go to the structure tab. enter image description here

step 2: click on change tab for the column you want to auto increment. In my case, i am changing for id column. enter image description here

step 3: check the AI(autoincrement ) column enter image description here

And you are done!

Abhishek
  • 546
  • 5
  • 13