Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

How to keep ordering of records in a database table

By: a guest on Feb 22nd, 2012  |  syntax: None  |  size: 0.44 KB  |  views: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. UPDATE YOUR_TABLE
  2.    SET sort_order = sort_order + 1
  3.  WHERE sort_order >= 2
  4.  
  5. INSERT INTO YOUR_TABLE
  6.   (value, sort_order)
  7. VALUES('new value', 2)
  8.        
  9. UPDATE YOUR_TABLE
  10.    SET sort_order = sort_order + 1
  11.  WHERE sort_order >= 2
  12.  
  13. INSERT INTO YOUR_TABLE
  14.   (value, sort_order)
  15. VALUES('new value', 2)
  16.        
  17. UPDATE YOUR_TABLE
  18.    SET sort_order = sort_order + 1
  19.  WHERE sort_order >= 2
  20.  
  21. INSERT INTO YOUR_TABLE
  22.   (value, sort_order)
  23. VALUES('new value', 2)