Entity Relationship Diagram
엔티티 관계 다이어그램
CREATE TABLE user (
id int PRIMARY KEY AUTO_INCREMENT,
name varchar(255),
email varchar(255),
roleId int
);
CREATE TABLE content (
id int PRIMARY KEY AUTO_INCREMENT,
title varchar(255),
body varchar(255),
created_at timestamp default current_timestamp,
userId int
);
CREATE TABLE role (
id int PRIMARY KEY AUTO_INCREMENT,
name varchar(255),
);
CREATE TABLE category (
id int PRIMARY KEY AUTO_INCREMENT,
name varchar(255)
);
CREATE TABLE content_category (
id int PRIMARY KEY AUTO_INCREMENT,
contentId int,
categoryId int
);
ALTER TABLE content ADD FOREIGN KEY (userId) REFERENCES user(id);
ALTER TABLE user ADD FOREIGN KEY (roleId) REFERENCES role(id);
ALTER TABLE content_category ADD FOREIGN KEY (contentId) REFERENCES content(id);
ALTER TABLE content_category ADD FOREIGN KEY (categoryId) REFERENCES category(id);
모든 데이터가 NULL 값을 허용하지 않기 때문에 타입 설정 뒤에 NOT NULL을 작성해줘야 한다.
CREATE TABLE user (
id int not NULL PRIMARY KEY auto_increment default NULL,
name varchar(255) not NULL default NULL,
email varchar(255) not NULL default NULL,
roleId int,
);
CREATE TABLE content (
id int not NULL PRIMARY KEY AUTO_INCREMENT,
title varchar(255) not NULL DEFAULT NULL,
body varchar(255) not NULL DEFAULT NULL,
created_at timestamp not NULL DEFAULT CURRENT_TIMESTAMP,
userId int DEFAULT NULL,
);
CREATE TABLE role (
id int not NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) not NULL
);
CREATE TABLE category (
id int not NULL PRIMARY KEY AUTO_INCREMENT,
name varchar(255) not NULL
);
CREATE TABLE content_category (
id int not NULL PRIMARY KEY AUTO_INCREMENT,
contentId int not NULL,
categoryId int not NULL
);
ALTER TABLE content ADD FOREIGN KEY (userId) REFERENCES user (id);
ALTER TABLE user ADD FOREIGN KEY (roleId) REFERENCES role (id);
ALTER TABLE content_category ADD FOREIGN KEY (contentId) REFERENCES content (id);
ALTER TABLE content_category ADD FOREIGN KEY (categoryId) REFERENCES category (id);
다 비슷하게 작성했지만 오잉 지금 유어클래스 확인하니까
created_at
관련이 사라져있다. ㅠㅠ timestamp타입을 현재 시간으로 작성해주는 속성이었는데current_timestamp
였던걸로 기억