mysql 更新历史数据Id为自增

mysql 更新历史数据Id为自增_第1张图片

begin;
DROP TABLE temp_table;
CREATE TABLE temp_table LIKE table;
ALTER TABLE `temp_table` MODIFY COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY ( `id` );
INSERT INTO temp_table ( url, title, time, info, source, html, type ) SELECT
url,title,time,info,source,html,type FROM	table;
DELETE FROM	table WHERE	1 = 1;
ALTER TABLE `table` MODIFY COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY ( `id` );
INSERT INTO table SELECT * FROM temp_table;
SELECT	* FROM	temp_table;
SELECT	* FROM	table;
commit;

你可能感兴趣的:(sql,mysql)