If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Changing Field positions in an existing table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-17-04, 14:18
hynding hynding is offline
Registered User
 
Join Date: May 2004
Location: Los Angeles, CA
Posts: 2
Changing Field positions in an existing table

I was wondering if there was a way to easily order the fields of a table that display from a "SHOW COLUMNS FROM table_name".

I assumed this might be possible with an "ALTER TABLE table_name MODIFY ..." command but I haven't been able to get anything to work. I noticed there is syntax for "ALTER TABLE MODIFY" that could prove useful (FIRST | BEFORE | AFTER) but on all my attempts I couldn't get anything to work.

I know I could go around all this by just dumping my table and re-creating it with the field orders I intended but I figured MySQL had an easier way I could do this with a few simple commands.

Thanks in advance...
Reply With Quote
  #2 (permalink)  
Old 05-17-04, 14:28
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Use something as simple as
Code:
ALTER table tablename MODIFY foo int AFTER bar;
you need the int (or char or char(15) or whatever) for the columntype after the first column so the database knows what type of data is stored in the column.
Reply With Quote
  #3 (permalink)  
Old 05-17-04, 15:06
hynding hynding is offline
Registered User
 
Join Date: May 2004
Location: Los Angeles, CA
Posts: 2
I don't know what is up but MySQL sends me an error 1064 message for 'AFTER bar' using the example above. Does anyone else experience this?
Reply With Quote
  #4 (permalink)  
Old 05-17-04, 22:32
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
What version of mysql are you using? I can't think that it should matter but I think 1064 errors crop up when you are using a version of mysql that isn't compatible with the code you are attempting (such as using a subquery before 4.1 or whatever version it starts with). Rudy or Pat can you clarify if I am right with this line of thinking?
Reply With Quote
  #5 (permalink)  
Old 05-18-04, 14:31
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Download the GUI from here and it does it for you.
http://www.mysqlfront.de/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On