How to set initial value and auto increment in MySQL?

前端 未结 10 1870
Happy的楠姐
Happy的楠姐 2020-11-22 13:40

How do I set the initial value for an \"id\" column in a MySQL table that start from 1001?

I want to do an insert \"INSERT INTO users (name, email) VALUES (\'{

相关标签:
10条回答
  • 2020-11-22 14:28

    For this you have to set AUTO_INCREMENT value

    ALTER TABLE tablename AUTO_INCREMENT = <INITIAL_VALUE>
    

    Example

    ALTER TABLE tablename AUTO_INCREMENT = 101
    
    0 讨论(0)
  • 2020-11-22 14:29

    Alternatively, If you are too lazy to write the SQL query. Then this solution is for you.

    1. Open phpMyAdmin
    2. Select desired Table
    3. Click on Operations tab
    4. Set your desired initial Value for AUTO_INCREMENT
    5. Done..!
    0 讨论(0)
  • 2020-11-22 14:32

    With CREATE TABLE statement

    CREATE TABLE my_table (
      id INT UNSIGNED NOT NULL AUTO_INCREMENT,
      name VARCHAR(100) NOT NULL,
      PRIMARY KEY (id)
    ) AUTO_INCREMENT = 100;
    

    or with ALTER TABLE statement

    ALTER TABLE my_table AUTO_INCREMENT = 200;
    
    0 讨论(0)
  • 2020-11-22 14:38

    Also , in PHPMyAdmin , you can select table from left side(list of tables) then do this by going there.
    Operations Tab->Table Options->AUTO_INCREMENT.

    Now, Set your values and then press Go under the Table Options Box.

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