MySQL

(DB) 블로그에 필요한 DB 간단 버전

mynote6676 2025. 5. 13. 19:31
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(
	comment_id int,
    user_id int,
    post_id int,
    story varchar(1000),
    primary key(comment_id),
    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(post_id,user_id),
    FOREIGN KEY  (user_id) REFERENCES user(user_id),
    FOREIGN KEY  (post_id) REFERENCES post(post_id)
);

 

'MySQL' 카테고리의 다른 글

(DB) MySQL 별칭, 변수 선언, IF 문 - 18  (0) 2025.05.16
(DB)MySQL JOIN - 17  (0) 2025.05.14
(DB) ERD 다이어 그램 만들어 보기 - 16  (1) 2025.05.13
(DB)관계 차수란? -15  (0) 2025.05.13
(DB)MySQL 기초 복습 하기 - 14  (0) 2025.05.13