-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
20 lines (18 loc) · 1019 Bytes
/
schema.sql
File metadata and controls
20 lines (18 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-- Drop existing tables if they exist (for development purposes)
DROP TABLE IF EXISTS comment;
DROP TABLE IF EXISTS discussion;
-- Create the discussion table
CREATE TABLE discussion (
id BIGINT AUTO_INCREMENT PRIMARY KEY, -- Unique identifier for each discussion
title VARCHAR(255) NOT NULL, -- Title of the discussion
content TEXT NOT NULL, -- Content of the discussion
user_id VARCHAR(255) NOT NULL, -- Identifier for the user who created the discussion
);
-- Create the comment table
CREATE TABLE comment (
id BIGINT AUTO_INCREMENT PRIMARY KEY, -- Unique identifier for each comment
content TEXT NOT NULL, -- Content of the comment
user_id VARCHAR(255) NOT NULL, -- Identifier for the user who created the comment
discussion_id BIGINT, -- Foreign key reference to the discussion
FOREIGN KEY (discussion_id) REFERENCES discussion(id) ON DELETE CASCADE -- Establishing foreign key relationship
);