--회원 정보 테이블 : members
drop table if exists members;
create table members(
userid varchar(20) not null, --아이디,pk
password varchar(50) not null, --비밀번호
name varchar(20) not null, --이름
email varchar(30) null, --이메일
phone varchar(20) null, --전화번호
birth date null, --생년월일
gender char(1) null check (gender in ('m','f')), --성별
address varchar(50) null, --주소
create_date datetime null, --생성일(가입일)
update_date datetime null, --수정일
constraint PRIMARY key(userid),
constraint UNIQUE(email)
);
insert into members(userid,password,name,create_date,update_date)
values('hong',password('1234'),'홍길동',sysdate(),sysdate());
insert into members(userid,password,name,create_date,update_date)
values('go',password('1234'),'고길동',sysdate(),sysdate());
insert into members(userid,password,name,email,create_date,update_date)
values('micol',password('1234'),'마이콜','micol@naver.com',sysdate(),sysdate());
insert into members(userid,password,name,email,create_date,update_date)
values('micol2',password('1234'),'마이콜2','micol2@naver.com',sysdate(),sysdate())
--블로그 글 : posts
drop table if exists posts;
create table posts(
num int AUTO_INCREMENT primary key,--순번pk
writer varchar(20) not null , --작성자 fk : users(userid)
title varchar(100) not null, --제목
content longtext null, --내용
create_date datetime null, --생성일
update_date datetime null, --수정일
constraint FOREIGN KEY(writer) REFERENCES members(userid)
);
insert into posts(writer,title,content,create_date,update_date)
values('hong','첫번째 글','테스트글입니다.',sysdate(),sysdate());
insert into posts(writer,title,content,create_date,update_date)
values('go','고길동의 첫번째 글','고길동 테스트글입니다.',sysdate(),sysdate());