SQL테이블 생성(2021.10.13)

김도형 (르베니아)·2021년 10월 13일
0

TIL

목록 보기
13/38

SQL 테이블

create table user(
	userId int(11) not null auto_increment,
	email varchar(50) not null,
	password varchar(40) not null,
    nickName varchar(40) not null,
	primary key(userId),
	index(email)
);

유저테이블 생성 userId를 기본키로 설정 자동으로 올라가게 설정
email, password, nickName
index는 email 사용

create table post(
	postId int(11) not null auto_increment,
	title varchar(50) not null,
	spec varchar(50),
	desc varchar(10),
	image varchar(255) default './images/BG.jpg',
	place int(11) not null,
	primary key(postId),
	index(name)
);

위와같음 postId 가 기본 키 자동으로 올라감

create table comment(
	commentId int(11) not null auto_increment,
	time timestamp default current_timestamp,
	nickname varchar(50) default '삭제된 유저',
	commet varchar(50) default null,
	upperPost int(20) not null,
	primary key(commentId),
	foreign key(upperPost)REFERENCES post(postId) ON DELETE CASCADE ON UPDATE CASCADE,
	index(nickname)
)

위와 같으나 commentId가 기본 key
post의 postId값이 upperPost로 들어감 바뀌면 자동으로 업데이트

create table wish(
	Id int(11) not null auto_increment,
	userId int(20) not null,
	postId int(20) not null,
	primary key(Id),
	foreign key(postId)REFERENCES post(postId) ON DELETE CASCADE ON UPDATE CASCADE,
    foreign key(userId)REFERENCES user(userId) ON DELETE CASCADE ON UPDATE CASCADE,
	index(userId)
)

이거는 확신이 없음
쿼리문 "" 무족건..

profile
한다. 간다. 해낸다.

0개의 댓글