Home  >  Article  >  Database  >  How to set auto-increment id in mysql

How to set auto-increment id in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-12-15 14:23:0735885browse

Mysql method to set auto-increasing id: First create the database, select Create Table; then when designing the table fields, the last parameter AI of the id column is auto-increasing, just check it.

How to set auto-increment id in mysql

The operating environment of this tutorial: windows7 system, mysql8.0.22, thinkpad t480 computer.

Related free learning recommendations: mysql database(Video)

##mysql Method to set auto-increment id:

1. Open MySQL Workbench, create a database, right-click Tables, and select Create Table

How to set auto-increment id in mysql

2 . When designing table fields, the last parameter AI (Auto Increment) of the id column is auto-increment. Just check it. It should be noted that it must be defined as INT type and must be set as an index. In this example, id is set as the primary key and defaults to the primary key index.

How to set auto-increment id in mysql

3. Execute Apply to create the table

How to set auto-increment id in mysql

4. You can also create the table through SQL commands

How to set auto-increment id in mysql

5. After the creation is successful, we insert a record and observe that the id column automatically grows to 1

How to set auto-increment id in mysql

6. In mysql, we can manually assign values ​​to self-increasing columns

How to set auto-increment id in mysql

7. After assignment, the records that will self-increase in the future will be based on our assignment. 1, here should be the maximum Based on the value 1

How to set auto-increment id in mysql

8. If you want to clear the table and start assigning values ​​again, you need to execute the truncate command

How to set auto-increment id in mysql

Related free learning recommendations:

php programming (video)

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

Statement:
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