38 lines
1.1 KiB
SQL
38 lines
1.1 KiB
SQL
CREATE TABLE users (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
username VARCHAR(50) UNIQUE NOT NULL,
|
|
email VARCHAR(100) UNIQUE NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE posts (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
user_id INT,
|
|
title VARCHAR(255) NOT NULL,
|
|
content TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
);
|
|
|
|
CREATE TABLE comments (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
post_id INT,
|
|
user_id INT,
|
|
content TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (post_id) REFERENCES posts(id),
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
);
|
|
|
|
INSERT INTO users (username, email) VALUES
|
|
('john_doe', 'john@example.com'),
|
|
('jane_smith', 'jane@example.com');
|
|
|
|
INSERT INTO posts (user_id, title, content) VALUES
|
|
(1, 'First Post', 'This is the content of the first post.'),
|
|
(2, 'Hello World', 'Hello everyone! This is my first post.');
|
|
|
|
INSERT INTO comments (post_id, user_id, content) VALUES
|
|
(1, 2, 'Great post!'),
|
|
(2, 1, 'Welcome to the community!');
|