Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. INSERT INTO table (color, size) VALUES ('blue', '18') ...
  2.  
  3. CREATE TABLE `firm_pref` (
  4. `id` int(9) NOT NULL AUTO_INCREMENT,
  5. `firm_id` int(9) NOT NULL, //user_id in this case
  6. `header_title` varchar(99) NOT NULL,
  7. `statement` varchar(99) NOT NULL,
  8. `footer_content` varchar(99) NOT NULL,
  9. PRIMARY KEY (`id`)
  10. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
  11.  
  12. INSERT INTO table (user_id, color, size) VALUES (NULL, 'blue', 18);
  13.  
  14. CREATE TABLE `prefs` (
  15. `id` int(9) NOT NULL AUTO_INCREMENT,
  16. `firm_id` int(9) NOT NULL,
  17. ...
  18. PRIMARY KEY (`id`),
  19. UNIQUE KEY (`firm_id`)
  20. );
  21.  
  22. INSERT INTO prefs(firm_id, header_title, statement, footer_content)
  23. VALUES(17, 'blue', '18', 'some_footer')
  24. ON DUPLICATE KEY UPDATE
  25. header_title = 'blue',
  26. statement = '18',
  27. footer_content = 'some_footer';
  28.  
  29. id | name
  30. =========
  31. 1 | color
  32. 2 | size
  33.  
  34. id | name
  35. ================
  36. 1 | Martin Bean
  37.  
  38. option_id | user_id | value
  39. ===========================
  40. 1 | 1 | Blue
  41. 2 | 1 | Large
  42.  
  43. DELETE FROM `options_users`
  44. WHERE `user_id` = @user_id;
  45.  
  46. INSERT INTO `options_users` (`option_id`, `user_id`, `value`)
  47. VALUES (1, @user_id, 'Blue'), (2, @user_id, 'Large');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement