Jump to content


Photo

Switching order of columns?


  • Please log in to reply
4 replies to this topic

#1 Fira

Fira
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 24 September 2006 - 12:54 AM

Is it possible to change the order of the columns in a table?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 September 2006 - 01:13 AM

Why would you want to do that?  It's the order in which you display retrieved data that's important, isn't it?
Legend has it that reading the manual never killed anyone.
My site

#3 Fira

Fira
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 24 September 2006 - 05:24 AM

Why would you want to do that?  It's the order in which you display retrieved data that's important, isn't it?

Yes, but one of my primary indices "id" is listed as my sixth column. It'd be easier to browse and keep track if I could change the position of "id" to first position.

#4 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 24 September 2006 - 11:57 AM

I don't know of a way to move the column only. You can use the CHANGE and MODIFY options for "ALTER TABLE" to move it but you'll have to redefine the column.

eg:
ALTER TABLE tablename MODIFY columnname INT NOT NULL AUTO_INCREMENT FIRST

or

ALTER TABLE tablename MODIFY columnname INT NOT NULL AUTO_INCREMENT AFTER othercolumn

http://dev.mysql.com...lter-table.html

Be careful when writing the column definition. If the wrong definition is given you may alter the contents of the column.

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 25 September 2006 - 03:53 AM

There isn't a way to move a column because it's totally unnecessary.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users