Home > Database > Mysql Tutorial > How to set auto-increment field in existing table in mysql

How to set auto-increment field in existing table in mysql

coldplay.xixi
Release: 2022-12-30 11:11:20
Original
6311 people have browsed it

Mysql method to set auto-increment fields in an existing table: 1. Add a field, the code is [alter table xiami add id int;]; 2. Modify the field, the code is [alter tabel xiami change id id auto_increment].

How to set auto-increment field in existing table in mysql

The operating environment of this tutorial: Windows 7 system, mysql version 8.0.22, DELL G3 computer. This method is suitable for all brands of computers.

Related free learning recommendations: mysql video tutorial

mysql sets auto-increment in existing tables Field method:

Step 1: Add field

alter table xiami add id int;
Copy after login

Step 2: Modify field

alter tabel xiami change id id auto_increment not null primary key;
Copy after login

Question:

Records in the table The number is 3929966

Query OK, 3929966 rows affected (2 min 8.09 sec)
Records: 3929966  Duplicates: 0  Warnings: 0  
查看创建表命令时,auto_increment为3932618
>> show create table xiami;
...
ENGINE=InnoDB AUTO_INCREMENT=3932618 DEFAULT CHARSET=utf8
Copy after login

The above is the detailed content of How to set auto-increment field in existing table 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