Solved

MySQL - Changing order of fields

Posted on 2001-07-10
8
333 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

751 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