• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

MySQL - Changing order of fields

Hi!

What's the best way of changing the order of fields in a MySQL database.

eg. There are 4 fields in a table.

id
surname
firstname
password

How do you change the order to...

id
password
firstname
surname


Cheers,

Mel
0
melvynmyers
Asked:
melvynmyers
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Why do you want to change the order of the fields? For the display, you can (and should) always query the fields in the order you want, and if you are developing a software on your own, you don't care the order.
I'm not sure, but MySQL should support views, in which you can order the fields as you like, and issue the SELECT * FROM YourView as you want...
CHeers
0
 
melvynmyersAuthor Commented:
The main reason is for commands like...

INSERT INTO table VALUES ('abc','123','etc','etc');


It makes life a little easier for me.

Cheers,

Mel

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
If you build the view(s) as i mentionned, you should be able to insert into the view also...
Not sure because i'm not MySQL expert, but that works for all the databases i know of (SQL Server, Oracle, Access)
CHeers
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
ahoorCommented:
So what's wrong with giving a column list?

INSERT INTO table (id, password, firstname,surname)
VALUES ('abc','123','etc','etc');


Arjan


0
 
melvynmyersAuthor Commented:
angel, I don't believe MySQL supprts views.

Arjan, thanks for your input. Your solution will work, but ideally I still want to change the field order.

Cheers!

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
As i said, i'm not a MySQL expert...
But in any database, you can only drop and recreate the table. To maintain the data, you can copy it to a temporary table...

CHeers
0
 
nico5038Commented:

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - Answered by: angelIII
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
JgouldCommented:
Question has been closed as per recommendation

JGould-EE Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now