Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rearrange Mysql Columns

Status
Not open for further replies.

Iverson3

Programmer
Aug 6, 2004
10
CA
Hi all,

I recently created a table with mysql. To simplify the matter, let's say the table has 3 fields: Name, Sex, Age.

Now, I would like to drop Sex and add one more new column named Location. By default, the new Table should have the following column order: Name, Age, Location.

Is there anyways to rearrange it so that it becomes Name, Location, Age?

or could I modify the column Sex so it become Location?

Thanks in advance for the advice,
 
You could do it in one step with:
[tt]
ALTER TABLE tbl CHANGE sex location CHAR(20);
[/tt]

However, that would leave you with the location field containing sex information.

Otherwise you could use a two-step approach:
[tt]
ALTER TABLE tbl DROP sex;
ALTER TABLE tbl ADD location CHAR(20) AFTER name;
[/tt]



-----
ALTER world DROP injustice, ADD peace;
 
Hi,

Thanks for the solution provided, it's exactly what i m after
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top