-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhase4.txt
29 lines (24 loc) · 841 Bytes
/
Phase4.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- INDEX on users
CREATE INDEX idx_users_username ON users (username);
CREATE INDEX idx_users_phone_number ON users (phone_number);
-- INDEX on user_contacts
CREATE INDEX idx_user_contacts_contact_id ON user_contacts (contact_id);
-- Transaction
BEGIN;
INSERT INTO users (username, password, first_name, last_name, phone_number)
VALUES ('johndoe', '123456', 'John', 'Doe', '+228-363-521-6763');
COMMIT;
BEGIN;
WITH new_user_id AS (
SELECT user_id FROM users WHERE username = 'johndoe'
)
INSERT INTO user_sessions (user_id, device_id, device_type)
SELECT user_id, '76543', 'LG' FROM new_user_id;
ROLLBACK;
BEGIN;
WITH new_user_id AS (
SELECT user_id FROM users WHERE username = 'johndoe'
)
INSERT INTO user_sessions (user_id, device_id, device_type)
SELECT user_id, '6481', 'Apple' FROM new_user_id;
COMMIT;