Forum Moderators: open
I know how to add and delete columns to my current tables, to make them match the tables on my new database. However, I dont know how to re-arrange the order of the columns in the table.
For example, my current table, holding all the data I want to transfer, has columns in this order:
CREATE TABLE `phpbb_topics` (
`topic_id` mediumint(8) unsigned NOT NULL auto_increment,
`forum_id` smallint(8) unsigned NOT NULL default '0',
`topic_title` varchar(60) NOT NULL default '',
`topic_poster` mediumint(8) NOT NULL default '0',
`topic_time` int(11) NOT NULL default '0',
`topic_views` mediumint(8) unsigned NOT NULL default '0',
`topic_replies` mediumint(8) unsigned NOT NULL default '0',
`topic_status` tinyint(3) NOT NULL default '0',
`topic_vote` tinyint(1) NOT NULL default '0',
`topic_type` tinyint(3) NOT NULL default '0',
`topic_last_post_id` mediumint(8) NOT NULL default '0',
`topic_first_post_id` mediumint(8) unsigned NOT NULL default '0',
`answer_status` tinyint(1) NOT NULL default '0',
`topic_moved_id` mediumint(8) unsigned NOT NULL default '0',
`topic_attachment` tinyint(1) NOT NULL default '0',
`topic_icon` tinyint(2) NOT NULL default '0',
`rating_rank_id` smallint(5) NOT NULL default '0',
`title_compl_infos` varchar(255) default NULL,
`topic_priority` smallint(6) NOT NULL default '0',
PRIMARY KEY (`topic_id`),
KEY `forum_id` (`forum_id`),
KEY `topic_moved_id` (`topic_moved_id`),
KEY `topic_status` (`topic_status`),
KEY `topic_type` (`topic_type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1217 ;
The columns in question are `topic_last_post_id` and `topic_first_post_id` . In the NEW database, `topic_first_post_id` comes before `topic_last_post_id` . So if I export the data, then import it to the new database the data will not be in the correct order. Here is the table structure in the new database:
CREATE TABLE `phpbb_topics` (
`topic_id` mediumint(8) unsigned NOT NULL auto_increment,
`forum_id` smallint(8) unsigned NOT NULL default '0',
`topic_title` varchar(120) NOT NULL default '',
`topic_poster` mediumint(8) NOT NULL default '0',
`topic_time` int(11) NOT NULL default '0',
`topic_views` mediumint(8) unsigned NOT NULL default '0',
`topic_replies` mediumint(8) unsigned NOT NULL default '0',
`topic_status` tinyint(3) NOT NULL default '0',
`topic_vote` tinyint(1) NOT NULL default '0',
`topic_type` tinyint(3) NOT NULL default '0',
`topic_first_post_id` mediumint(8) unsigned NOT NULL default '0',
`topic_last_post_id` mediumint(8) unsigned NOT NULL default '0',
`answer_status` tinyint(1) unsigned NOT NULL default '0',
`topic_moved_id` mediumint(8) unsigned NOT NULL default '0',
`topic_attachment` tinyint(1) NOT NULL default '0',
`topic_icon` tinyint(2) unsigned NOT NULL default '0',
`rating_rank_id` smallint(5) unsigned NOT NULL default '0',
`title_compl_infos` varchar(255) default NULL,
`topic_priority` smallint(6) NOT NULL default '0',
PRIMARY KEY (`topic_id`),
KEY `forum_id` (`forum_id`),
KEY `topic_moved_id` (`topic_moved_id`),
KEY `topic_status` (`topic_status`),
KEY `topic_type` (`topic_type`),
KEY `topics_ratingrankid` (`rating_rank_id`),
FULLTEXT KEY `topic_title` (`topic_title`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1221 ;
How can I rearrange the table's column order on my current database, without losing all the data?
Next, all you need to do is some ALTER TABLE [dev.mysql.com] work.
On the reference page it says:
MODIFY [COLUMN] column_definition [FIRST ¦ AFTER col_name]
So I am trying this is in phpmyadmin:
ALTER TABLE phpbb_topics (
MODIFY `topic_last_post_id` CHANGE AFTER `topic_first_post_id`
);
I have tried many variations and just can not get it. Can anyone help me with the syntax to use to do this operation in phpmyadmin?
I have got most of my database already transfered, I am just stuck on this one table.
Thanks for providing my with that link!
[dev.mysql.com...]
So I tried:
ALTER TABLE nuke_bbtopics MODIFY COLUMN topic_last_post_id mediumint AFTER topic_first_post_id
and it worked like a charm. Thanks again for pointing me in the right direction!