How to set initial value and auto increment in MySQL?

前端 未结 10 1957
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:26

    First you need to add column for auto increment

    alter table users add column id int(5) NOT NULL AUTO_INCREMENT FIRST
    

    This query for add column at first. Now you have to reset auto increment initial value. So use this query

    alter table users AUTO_INCREMENT=1001
    

    Now your table started with 1001

提交回复
热议问题