我想用另一个表中的数据创建一个表,以便将 id 设置为某个 auto_increment 起始值。
这是我想用另一个表中的数据填充的表:
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| city | varchar(255) | YES | | NULL | |
| state | varchar(255) | YES | | NULL | |
| state_id | int(11) | YES | | NULL | |
| city_slug | varchar(255) | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
执行此查询后:
alter table table_temp auto_increment = 40499;
如果我做一个虚拟插入:
insert into table_temp (city, state, state_id, city_slug) values (1, 1, 1, 1);
它做了它的预期,即 id 以值 40499 开头
select * from table_temp;
+-------+------+-------+----------+-----------+
| id | city | state | state_id | city_slug |
+-------+------+-------+----------+-----------+
| 40499 | 1 | 1 | 1 | 1 |
+-------+------+-------+----------+-----------+
在截断表并再次执行 auto_increment 的 alter table 查询后,我尝试用另一个表中的数据填充同一个表:
insert into table_temp (city, state, state_id, city_slug) select city, state, state_id, city_slug from final_location;
但是 id 以默认 id 值 1 开头:
select * from table_temp limit 10;
+----+---------+---------+----------+-------------------+
| id | city | state | state_id | city_slug |
+----+---------+---------+----------+-------------------+
| 1 | Abatiá | Paraná | 242 | all-cidade-abatia |
+----+---------+---------+----------+-------------------+
对于如何解决这个问题,有任何的建议吗?