Jump to content

SWAP two PRIMARY keys


DiscoTrio

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/195370-swap-two-primary-keys/
Share on other sites

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.