On Wed, Jul 30, 2008 at 12:56 PM, Rob Wultsch <[EMAIL PROTECTED]> wrote: > On Wed, Jul 30, 2008 at 11:42 AM, Jerry Schwartz > <[EMAIL PROTECTED]> wrote: >> Is there any reasonable way of re-arranging the order of columns in a table >> without losing their data? The best I could come up with was to copy the >> table, empty it, and then do an INSERT . SELECT specifying the new order of >> the fields. > Something like > ALTER TABLE [TABLE] MODIFY [COLUMN] col_name column_definition > [FIRST | AFTER col_name] > shoudl work > > http://dev.mysql.com/doc/refman/5.0/en/alter-table.html >
I didn't have a mysql install handy at the time or original posting to include a demo. For the record Shawn H. Corey is correct. Anyways: mysql> create table t(c1 int,c2 int); Query OK, 0 rows affected (0.27 sec) mysql> insert into t values(1,2); Query OK, 1 row affected (0.19 sec) mysql> select * from t; +------+------+ | c1 | c2 | +------+------+ | 1 | 2 | +------+------+ 1 row in set (0.00 sec) mysql> ALTER TABLE t MODIFY c1 int AFTER c2; Query OK, 1 row affected (0.52 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> select * from t; +------+------+ | c2 | c1 | +------+------+ | 2 | 1 | +------+------+ 1 row in set ( 0.00 sec) -- Rob Wultsch -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]