Author Topic: SWAP two PRIMARY keys  (Read 442 times)

0 Members and 1 Guest are viewing this topic.

Offline DiscoTrioTopic starter

  • Enthusiast
  • Posts: 78
    • View Profile
SWAP two PRIMARY keys
« on: March 15, 2010, 06:08:07 PM »
So im making a php button to click (like an up or down arrow) to re-order a table but first I need a way to re-assign the primary key 'id' that is auto-increment.

Heres a quick look at the table:

idmediatitlecontenttext
1photoSample item 1http://media-cdn.tripadvisor.com/media/photo-s/00/...Lorem ipsum dolor sit amet, consectetur adipiscing...
2videoSample item 2media/himmler-poznan-large.flvIn quis nisi tellus, ut gravida elit. Sed aliquet,...

So anyways see the id?  Its auto increment and primary...  I need a sql statement to switch the two numbers that I can run from php variables.

Thank you.

Offline premiso

  • Karma Chameleon
  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,671
  • Gender: Female
  • effing right
    • View Profile
    • PHP Help
Re: SWAP two PRIMARY keys
« Reply #1 on: March 15, 2010, 06:52:00 PM »
You should be able to run an UPDATE on the primary and auto_increment id, albiet it is generally not recommended, instead it would be recommended to have a separate column for "order" and then order it by that and you can use that to display it.