我偶然发现了一个非常奇怪的行为:
想象一下,我们有一个表客户:
MariaDB [connections]> describe customers;
+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| customerId | int(11) | NO | PRI | NULL | auto_increment |
| customerName | varchar(50) | NO | | NULL | |
+--------------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
插入几个值:
insert into customers(customerName) values('Foo');
insert into customers(customerName) values('Bar');
Run Code Online (Sandbox Code Playgroud)
然后删除所有内容并重置自动增量:
DELETE FROM customers;
ALTER TABLE customers AUTO_INCREMENT = 0;
Run Code Online (Sandbox Code Playgroud)
现在,使用customerId = 0插入一个新值:
INSERT INTO customers(customerId,customerName) VALUES(0,'Site owner');
Run Code Online (Sandbox Code Playgroud)
并看到结果: …