29
loading...
This website collects cookies to deliver better user experience
CREATE TABLE User (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
email TEXT,
password TEXT
);
SELECT * FROM users
INSERT INTO users (name, email, password) VALUES ('John Doe', '[email protected]', 'ajn1489valpa')
UPDATE users SET name = 'John Doe' WHERE id = 1
DELETE FROM users WHERE id = 1
CREATE TABLE profiles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
bio TEXT,
FOREIGN KEY (user_id) REFERENCES users(id)
);
profiles
table. user_id
column references the id
column in the users
table. user
.users
table. profiles
table.CREATE TABLE posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
title TEXT,
body TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
post_id INTEGER,
user_id INTEGER,
body TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
FOREIGN KEY (post_id) REFERENCES posts(id)
FOREIGN KEY (user_id) REFERENCES users(id)
);
posts
table, we have a user_id
column that references the id
column in the users
table. user
. But a user can have many posts.post_id
column references the id
column in the posts
table. user_id
column references the id column in the users
table.