Advertisement
pcwizz

user-create

Feb 5th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.71 KB | None | 0 0
  1. #Insert User row
  2. INSERT INTO
  3.  `USER`
  4. (
  5.  `name`,
  6.  `contactNumber`,
  7.  `email`,
  8.  `password`,
  9.  `salt`,
  10.  `gender`
  11. )
  12.  VALUES
  13.  (
  14. ?,
  15. ?,
  16. ?,
  17. ?,
  18. ?,
  19. ?
  20. );
  21. #store the id of the user
  22. SET @USER_id=LAST_INSERT_ID();
  23. #insert the users address
  24. INSERT INTO
  25. `ADDRESS`
  26. (
  27. lineOne,
  28. postcode
  29. )
  30. VALUES
  31. (
  32. ?,
  33. ?
  34. );
  35. #store the id of the users address
  36. SET @ADDRESS_id = LAST_INSERT_ID();
  37. #Insert row in linking table to link the address amd the user
  38. INSERT INTO
  39. USER_ADDRESS
  40. (
  41. USER_id,
  42. ADDRESS_id
  43. )
  44. VALUES
  45. (
  46. @USER_id,
  47. @ADDRESS_id
  48. );
  49. #link user to a group
  50. INSERT INTO
  51. USER_GROUP
  52. (
  53. USER_id,
  54. GROUP_id
  55. )
  56. VALUES
  57. (
  58. @USER_id,
  59. #sub query to find group id
  60.     (
  61.     SELECT
  62.     id
  63.     FROM
  64.     GROUP
  65.     WHERE
  66.     name=?
  67.     )
  68. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement