Link to home
Start Free TrialLog in
Avatar of melvynmyers
melvynmyers

asked on

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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
Avatar of melvynmyers
melvynmyers

ASKER

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

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
So what's wrong with giving a column list?

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


Arjan


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!

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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)
Question has been closed as per recommendation

JGould-EE Moderator