How to add auto-increment to column in mysql database using phpmyadmin?

后端 未结 5 898
滥情空心
滥情空心 2020-12-30 10:17

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?

相关标签:
5条回答
  • 2020-12-30 10:39

    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)

    0 讨论(0)
  • 2020-12-30 10:40

    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

    0 讨论(0)
  • 2020-12-30 10:49

    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.

    0 讨论(0)
  • 2020-12-30 10:54

    You can add it like this

    ALTER TABLE your_table
    MODIFY some_column INT NOT NULL AUTO_INCREMENT;
    
    0 讨论(0)
  • 2020-12-30 11:04

    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

    0 讨论(0)
提交回复
热议问题