-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sql
More file actions
40 lines (33 loc) · 1.05 KB
/
Copy pathtest.sql
File metadata and controls
40 lines (33 loc) · 1.05 KB
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
30
31
32
33
34
35
36
37
38
39
40
-- test cases generated BY ChatGPT
SELECT id, name, email FROM Users WHERE active = true;
UPDATE users SET last_login = now() WHERE id = 1;
DELETE FROM sessions WHERE user_id = 1;
INSERT INTO orders (user_id, product_id, quantity) VALUES (1, 2, 3);
SELECT a.name, b.amount
FROM customers a
INNER JOIN transactions b ON a.id = b.customer_id
WHERE a.country = 'USA and Canada'
AND b.amount > 100
ORDER BY b.date DESC;
CREATE TABLE products (
id serial PRIMARY KEY,
name varchar(100) NOT NULL,
price decimal(10, 2) NOT NULL CHECK (price > 0)
);
CREATE TABLE orders (
id serial PRIMARY KEY,
user_id int REFERENCES users(id),
product_id int REFERENCES products(id),
quantity int CHECK (quantity > 0)
);
CREATE PROCEDURE get_customer_balance(IN customer_id int)
BEGIN
DECLARE balance decimal(10, 2);
SELECT sum(amount) INTO balance FROM transactions WHERE customer_id = customer_id;
SELECT balance;
END;
CREATE VIEW active_users AS
SELECT id, name, email
FROM users
WHERE active = true;
CREATE INDEX idx_user_email ON users (email);