List:General Discussion« Previous MessageNext Message »
From:Rob Wultsch Date:July 31 2008 11:44am
Subject:Re: Re-arranging fields
View as plain text  
On Wed, Jul 30, 2008 at 12:56 PM, Rob Wultsch <wultsch@stripped> wrote:
> On Wed, Jul 30, 2008 at 11:42 AM, Jerry Schwartz
> <jschwartz@stripped> 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
Thread
Re-arranging fieldsJerry Schwartz30 Jul
  • Re: Re-arranging fieldsRanjeet Walunj30 Jul
    • RE: Re-arranging fieldsJerry Schwartz31 Jul
      • RE: Re-arranging fieldsMr. Shawn H. Corey31 Jul
        • RE: Re-arranging fieldsJerry Schwartz31 Jul
          • RE: Re-arranging fieldsMr. Shawn H. Corey31 Jul
            • RE: Re-arranging fieldsJerry Schwartz31 Jul
  • Re: Re-arranging fieldsRob Wultsch30 Jul
    • Re: Re-arranging fieldsRob Wultsch31 Jul
    • RE: Re-arranging fieldsJerry Schwartz31 Jul
  • Re: Re-arranging fieldsMr. Shawn H. Corey30 Jul
    • RE: Re-arranging fieldsJerry Schwartz31 Jul
  • Re: Re-arranging fieldsMartijn Tonies31 Jul
    • RE: Re-arranging fieldsJerry Schwartz31 Jul