I know that I can reset the primary key in this way:
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;
But I’m wondering how I can adapt this to apply the primary key according to the timestamp in my timestamp column, i.e. the row with the oldest timestamp gets the value 1, the next oldest, the value 2, etc.
OUTPUT of 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
Create a new table called
users2that has the same structure asusers:Then run this statment:
For your specific table: