以下 php 代码在数据库中查找重复记录,删除所有相似的记录(但其中一条没有),按时间顺序重新排序所有数据,最后从 1 到 n 逐步重新编号所有行(id 字段)。
问题:当我执行这段代码时,表名“mytable”在“tmp”中发生了变化,一切都停止并出错了。
为什么这个?我该如何解决这个问题?
$creatmp = mysql_query("CREATE TABLE tmp AS SELECT * FROM mytable WHERE 1 GROUP BY name, surname, birthdate");
$cancqsos = mysql_query("DROP TABLE mytable");
$datmpaqsos = mysql_query("ALTER TABLE tmp RENAME TO mytable");
$creariordinoid = mysql_query("CREATE TABLE riordinoid LIKE mytable");
$popolariordinoid = mysql_query("INSERT INTO riordinoid SELECT * FROM qsos ORDER BY birthdate");
$svuotacampoid = mysql_query("ALTER TABLE `riordinoid` DROP `id`");
$ricontauno = mysql_query("ALTER TABLE `riordinoid` AUTO_INCREMENT = 1");
$ricontadue = mysql_query("ALTER TABLE `riordinoid` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;");
$svuotaqsos = mysql_query("DROP TABLE mytable");
$rinominariordinoid = mysql_query("ALTER TABLE riordinoid RENAME TO mytable");