summaryrefslogtreecommitdiff
path: root/samples/test.sql
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 20:22:09 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 20:22:09 +0100
commit5a8dbc6347b3541e84fe669b22c17ad3b715e258 (patch)
treeb148c450939688caaaeb4adac6f2faa1eaffe649 /samples/test.sql
downloadqwe-editor-5a8dbc6347b3541e84fe669b22c17ad3b715e258.tar.gz
Engage!
Diffstat (limited to 'samples/test.sql')
-rw-r--r--samples/test.sql45
1 files changed, 45 insertions, 0 deletions
diff --git a/samples/test.sql b/samples/test.sql
new file mode 100644
index 0000000..40311ef
--- /dev/null
+++ b/samples/test.sql
@@ -0,0 +1,45 @@
1-- Create a new table called 'users'
2CREATE TABLE users (
3 id SERIAL PRIMARY KEY,
4 username VARCHAR(50) NOT NULL UNIQUE,
5 email VARCHAR(100) NOT NULL UNIQUE,
6 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
7 active BOOLEAN DEFAULT TRUE
8);
9
10-- Insert some sample data
11INSERT INTO users (username, email) VALUES
12 ('john_doe', 'john@example.com'),
13 ('jane_smith', 'jane@example.com'),
14 ('bob_jones', 'bob@test.com');
15
16-- Select data with a condition
17SELECT * FROM users
18WHERE active = TRUE AND created_at > '2023-01-01';
19
20-- Update a record
21UPDATE users
22SET active = FALSE
23WHERE username = 'bob_jones';
24
25-- Join with another table
26SELECT u.username, p.title
27FROM users u
28JOIN posts p ON u.id = p.user_id
29WHERE u.active = TRUE
30ORDER BY p.created_at DESC;
31
32-- Create an index
33CREATE INDEX idx_users_email ON users(email);
34
35-- Create a view
36CREATE OR REPLACE VIEW active_users AS
37SELECT id, username, email
38FROM users
39WHERE active = TRUE;
40
41-- Delete a record
42DELETE FROM users WHERE id = 100;
43
44-- Drop the table
45-- DROP TABLE users;