Home > Database > Mysql Tutorial > How to set the conditions for auto-incrementing id in mysql?

How to set the conditions for auto-incrementing id in mysql?

青灯夜游
Release: 2020-09-27 17:22:11
Original
8552 people have browsed it

Mysql method to set the conditions for auto-increment id: 1. Set the id field as the primary key when creating the data table; 2. Use the "alter table table name modify id int(11) auto_increment;" statement as the id field Just add the auto_increment attribute.

How to set the conditions for auto-incrementing id in mysql?

When the PHP file executes the MySQL database insert statement, it is often necessary to execute the id auto-increment attribute. Otherwise, 0 will always be returned when the mysqli_insert_id function is executed.

If you want to implement id auto-increment, you need to set id as the primary key when creating the data table and set it to AUTO_INCREMENT.

How to set the conditions for auto-incrementing id in mysql?

Use SQL statements to set auto-increment for existing primary key fields

Step 1: Add the auto_increment attribute to id

alter table tablename modify id int(11) auto_increment;
Copy after login

Step 2: Set the initial value for the self-increasing value

alter table tablename auto_increment=10000;
Copy after login

More related free learning recommendations: mysql tutorial(video)

The above is the detailed content of How to set the conditions for auto-incrementing id in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template