Auto increment in phpmyadmin

前端 未结 9 2064
暗喜
暗喜 2020-11-28 05:19

I have an existing database using PHP, MySQL and phpMyAdmin.

When users become a member on my website, I need the system to create a unique membership number for the

相关标签:
9条回答
  • 2020-11-28 05:34

    @AmitKB, Your procedure is correct. Although this error

    Query error: #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

    can be solved by first marking the field as key(using the key icon with label primary),unless you have other key then it may not work.

    0 讨论(0)
  • 2020-11-28 05:35

    You cannot set a maximum value (other than choosing a datatype which cannot hold large numbers, but there are none that have the limit you're asking for). You can check that with LAST_INSERT_ID() after inserting to get the id of the newly created member, and if it is too big handle it in your application code (e.g., delete and reject the member).

    Why do you want an upper limit?

    0 讨论(0)
  • 2020-11-28 05:37

    This is due to the wp_terms, wp_termmeta and wp_term_taxonomy tables, which had all their ID's not set to AUTO_INCREMENT

    To do this go to phpmyadmin, click on the concern database, wp_terms table, click on structure Tab, at right side you will see a tab named A_I(AUTO_INCREMENT), check it and save (You are only doing this for the first option, in the case wp_term you are only doing it for term_id).

    Do the same for wp_termmeta and wp_term_taxonomy that will fix the issue.

    0 讨论(0)
  • 2020-11-28 05:39

    In phpMyAdmin, navigate to the table in question and click the "Operations" tab. On the left under Table Options you will be allowed to set the current AUTO_INCREMENT value.

    0 讨论(0)
  • 2020-11-28 05:44
    1. In "Structure" tab of your table
    2. Click on the pencil of the variable you want auto_increment
    3. under "Extra" tab choose "auto_increment"
    4. then go to "Operations" tab of your table
    5. Under "Table options" -> auto_increment type -> 10000
    0 讨论(0)
  • 2020-11-28 05:47

    Just run a simple MySQL query and set the auto increment number to whatever you want.

    ALTER TABLE `table_name` AUTO_INCREMENT=10000
    

    In terms of a maximum, as far as I am aware there is not one, nor is there any way to limit such number.

    It is perfectly safe, and common practice to set an id number as a primiary key, auto incrementing int. There are alternatives such as using PHP to generate membership numbers for you in a specific format and then checking the number does not exist prior to inserting, however for me personally I'd go with the primary id auto_inc value.

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