Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. mysql> desc Gallery;
  2.  
  3. +--------------+------------------+------+-----+-------------------+-----------------------------+
  4. | Field | Type | Null | Key | Default | Extra |
  5. +--------------+------------------+------+-----+-------------------+-----------------------------+
  6. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  7. | title | varchar(255) | NO | | NULL | |
  8. | subtitle | varchar(255) | NO | | NULL | |
  9. | description | varchar(5000) | NO | | NULL | |
  10. | date | datetime | NO | | NULL | |
  11. | isActive | tinyint(1) | NO | | NULL | |
  12. | lastModified | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
  13. +--------------+------------------+------+-----+-------------------+-----------------------------+
  14.  
  15. mysql> desc Image;
  16. +--------------+------------------+------+-----+-------------------+-----------------------------+
  17. | Field | Type | Null | Key | Default | Extra |
  18. +--------------+------------------+------+-----+-------------------+-----------------------------+
  19. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  20. | galleryId | int(10) unsigned | NO | MUL | NULL | |
  21. | description | varchar(250) | YES | | NULL | |
  22. | path | varchar(250) | NO | | NULL | |
  23. | lastModified | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
  24. +--------------+------------------+------+-----+-------------------+-----------------------------+
  25.  
  26. UPDATE table set order=order+1 where order>='orderValueOfItemYouCareAbout';
  27.  
  28. mysql> SELECT id, galleryId, description, displayOrder FROM Image ORDER BY displayOrder;
  29. +-----+-----------+----------------------------------+--------------+
  30. | id | galleryId | description | displayOrder |
  31. +-----+-----------+----------------------------------+--------------+
  32. | 271 | 20 | NULL | 1 |
  33. | 270 | 20 | Tracks leading into the ocean... | 2 |
  34. | 278 | 20 | NULL | 3 |
  35. +-----+-----------+----------------------------------+--------------+
  36. 3 rows in set (0.00 sec)
  37.  
  38. UPDATE Image SET displayOrder =
  39. CASE displayOrder
  40. WHEN 2 THEN 3
  41. WHEN 3 THEN 2
  42. END
  43. WHERE galleryId = 20
  44. AND displayOrder BETWEEN 2 AND 3;
  45.  
  46. mysql> SELECT id, galleryId, description, displayOrder FROM Image ORDER BY displayOrder;
  47. +-----+-----------+----------------------------------+--------------+
  48. | id | galleryId | description | displayOrder |
  49. +-----+-----------+----------------------------------+--------------+
  50. | 271 | 20 | NULL | 1 |
  51. | 278 | 20 | NULL | 2 |
  52. | 270 | 20 | Tracks leading into the ocean... | 3 |
  53. +-----+-----------+----------------------------------+--------------+
  54. 3 rows in set (0.00 sec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement