使用mysql的存储过程进行批量操作
步骤说明
1. 创建存储过程
CREATE PROCEDURE `update_id`() BEGIN DECLARE current_num INT DEFAULT 1; DECLARE total_num INT DEFAULT (SELECT COUNT(*) FROM table_name); WHILE current_num<= total_num DO UPDATE table_name SET id = current_num WHERE id = (SELECT MAX(id) FROM table_name); SET current_num = current_num + 1; END WHILE; END
2. 执行存储过程
CALL update_id();
就可以批量修改mysql表格的id自增了