Nilai AUTO_INCRMENT MySQL bermula dari 1 tetapi kita boleh mengubahnya dalam dua cara-
Kita boleh menukar nilai permulaan AUTO_INCRMENT menggunakan pertanyaan ALTER TABLE seperti yang ditunjukkan di bawah-
Terjemahan Bahasa Cina ContohALTER TABLE table_name AUTO_INCREMENT = value;
mysql> Create Table EMP(id int NOT NULL PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(10)); Query OK, 0 rows affected (0.07 sec) mysql> Insert Into EMP(Name) Values('Aryan'); Query OK, 1 row affected (0.02 sec) mysql> Insert Into EMP(Name) Values('Yash'); Query OK, 1 row affected (0.04 sec) mysql> Select * from EMP; +----+-------+ | id | NAME | +----+-------+ | 1 | Aryan | | 2 | Yash | +----+-------+ 2 rows in set (0.00 sec)
mysql> Alter table emp auto_increment = 10; Query OK, 2 rows affected (0.25 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> Insert Into EMP(Name) Values('Daksh'); Query OK, 1 row affected (0.03 sec) mysql> Insert Into EMP(Name) Values('Shayra'); Query OK, 1 row affected (0.06 sec) mysql> Select * from EMP; +----+--------+ | id | NAME | +----+--------+ | 1 | Aryan | | 2 | Yash | | 10 | Daksh | | 11 | Shayra | +----+--------+ 4 rows in set (0.00 sec)
CREATE TABLE (Column1 INT PRIMARY KEY NOT NULL AUTO_INCREMENT, Column2 data type) AUTO_INCREMENT = value;
mysql> Create Table EMP1(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(10)) AUTO_INCREMENT = 100; Query OK, 0 rows affected (0.11 sec)
Atas ialah kandungan terperinci Bagaimanakah kita boleh menukar nombor permulaan MySQL AUTO_INCRMENT?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!