MySQL

blog 구성해보기

whs5758 2025. 5. 13. 17:56
create database blog;
use blog;

create table user(
    user_id int auto_increment,
    email varchar(50) unique not null,
    password varchar(50) not null,
    name varchar(50) not null,
    created_at timestamp default current_timestamp,
    primary key (user_id)
);

create table post(
post_id int auto_increment,
user_id int,
title varchar(50) not null,
story text,
created_at timestamp default current_timestamp,
primary key(post_id),
 FOREIGN KEY post_user (user_id) REFERENCES user(user_id)
);

create table comment(
    user_id int,
    post_id int,
    commemt_id int primary key auto_increment,
    story varchar(1000),
    created_at timestamp default current_timestamp,
    FOREIGN KEY comment_user (user_id) REFERENCES user(user_id),
    FOREIGN KEY commemt_post (post_id) REFERENCES post(post_id)
);

create table post_detail(
	post_class varchar(50) not null,
    post_id int,
    FOREIGN KEY post_detail (post_id) REFERENCES post(post_id)
);

create table user_detail(
	user_class varchar(50) not null,
    user_id int,
    FOREIGN KEY user_detail (user_id) REFERENCES user(user_id)
);

create table user_post_like(
    user_id int,
    post_id int,
    primary key(user_id, post_id),
    FOREIGN KEY like_user (user_id) REFERENCES user(user_id),
    FOREIGN KEY like_post (post_id) REFERENCES post(post_id)
);

'MySQL' 카테고리의 다른 글

MySQL 별칭, 변수 선언, IF 문  (0) 2025.05.15
MySQL JOIN  (0) 2025.05.14
ERD 다이어 그램 만들어 보기  (2) 2025.05.13
관계 차수란?  (0) 2025.05.13
PRIMARY KEY, FOREIGN KEY, UNIQUE KEY 란 뭘까?  (0) 2025.05.12