我知道我可以通过这种方式重置主键:
ALTER TABLE `users` DROP `id`;
ALTER TABLE `users` AUTO_INCREMENT = 1;
ALTER TABLE `users` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;
但我想知道如何调整它以根据我的时间戳列中的时间戳应用主键,即具有最旧时间戳的行获得值 1,下一个最旧的值 2,等等。
SHOW CREATE TABLE 的输出
CREATE TABLE `tracks` (
`id` int(10) unsigned NOT NULL auto_increment,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
`from_user` varchar(50) NOT NULL,
`source_filename` varchar(80) NOT NULL,
`uploaded_page` varchar(50) NOT NULL,
`operating_system` varchar(50) NOT NULL,
`browser` varchar(50) NOT NULL,
`os_browser_version` varchar(200) NOT NULL,
`title` varchar(100) NOT NULL,
`artist` varchar(60) NOT NULL,
`album` varchar(120) NOT NULL,
`genre` varchar(120) NOT NULL,
`format` varchar(10) NOT NULL,
`bitrate` mediumint(9) NOT NULL,
`conversion_needed` tinyint(1) NOT NULL COMMENT 'if not mp3, or higher than 192kbps',
`conversion_successful` tinyint(1) NOT NULL,
`art_extracted` tinyint(1) NOT NULL,
`art_location` varchar(200) NOT NULL,
`file_location` varchar(200) NOT NULL,
`status` varchar(500) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=96 DEFAULT CHARSET=utf8