-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransaction.cql
23 lines (18 loc) · 1 KB
/
transaction.cql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Add a new user with duplicate email check
BEGIN TRANSACTION
-- Find any existing users with same email
LET existCheck = (SELECT user_id FROM users.user_by_email WHERE email='[email protected]');
-- If email isn't in use, then add the new user
IF existCheck IS NULL THEN
INSERT INTO users.user(user_id, email, country, city)
VALUES (94813846-4366-11ed-b878-0242ac120002, '[email protected]', 'US', 'Windsor');
INSERT INTO users.user_by_email(email, user_id)
VALUES ('[email protected]', 94813846-4366-11ed-b878-0242ac120002);
INSERT INTO users.user_by_location(country, city, user_id)
VALUES ('US', 'Windsor', 94813846-4366-11ed-b878-0242ac120002);
END IF
COMMIT TRANSACTION;
-- Query user by email
SELECT * FROM users.user_by_email WHERE email='[email protected]';
-- Find users in a specific location
SELECT * FROM users.user_by_location WHERE country='US' AND city='Windsor';