Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #create temp table
- CREATE TEMPORARY TABLE temp_user_data
- (
- USER_id INT,
- name TEXT,
- contactNumber TEXT,
- email TEXT,
- password TEXT,
- salt TEXT,
- gender TEXT,
- ADDRESS_id INT,
- lineOne TEXT,
- postcode TEXT,
- GROUP_id INT
- );
- #populate temporary table
- INSERT INTO
- temp_user_data
- (
- `USER_id`,
- `name`,
- `contactNumber`,
- `email`,
- `password`,
- `salt`,
- `gender`,
- `ADDRESS_id`,
- `lineOne`,
- `postcode`,
- `GROUP_id`
- )
- VALUES
- (
- ?,#User_id
- ?,#name
- ?,#contactNumer
- ?,#email
- ?,#password
- ?,#salt
- ?,#gender
- ?,#ADDRESS_id
- ?,#lineOne
- ?,#postcode
- ? #GROUP_id
- );
- #Insert User row
- INSERT INTO
- `USER`
- (
- `id`,
- `name`,
- `contactNumber`,
- `email`,
- `password`,
- `salt`,
- `gender`
- )
- SELECT
- `USER_id`,
- `name`,
- `contactNumber`,
- `email`,
- `password`,
- `salt`,
- `gender`
- FROM
- temp_user_data;
- #insert the users address
- INSERT INTO
- `ADDRESS`
- (
- `id`,
- `lineOne`,
- `postcode`
- )
- SELECT
- `ADDRESS_id`,
- `lineOne`,
- `postcode`
- FROM
- temp_user_data;
- #Insert row in linking table to link the address and the user
- INSERT INTO
- USER_ADDRESS
- (
- USER_id,
- ADDRESS_id
- )
- SELECT
- `USER_id`,
- `ADDRESS_id`
- FROM
- temp_user_data;
- #link user to a group
- INSERT INTO
- USER_GROUP
- (
- USER_id,
- GROUP_id
- )
- SELECT
- `USER_id`,
- `GROUP_id`
- FROM
- temp_user_data
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement