Solved

MySQL - Changing order of fields

Posted on 2001-07-10
8
337 Views
Last Modified: 2006-11-17
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
Comment
Question by:melvynmyers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6269089
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
 
LVL 1

Author Comment

by:melvynmyers
ID: 6271746
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6271965
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
MongoDB Through a MySQL Lens

This article looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.

 
LVL 3

Expert Comment

by:ahoor
ID: 6272403
So what's wrong with giving a column list?

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


Arjan


0
 
LVL 1

Author Comment

by:melvynmyers
ID: 6275564
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6275801
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
 
LVL 54

Expert Comment

by:nico5038
ID: 7258959

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
 

Expert Comment

by:Jgould
ID: 7289055
Question has been closed as per recommendation

JGould-EE Moderator
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question