-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_table.txt
More file actions
51 lines (36 loc) · 1.9 KB
/
sql_table.txt
File metadata and controls
51 lines (36 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
create sequence seq_board;
create table tbl_board(
bno number(10,0),
title varchar2(200) not null, -- 제목
content varchar2(2000) not null, -- 내용
writer varchar2(50) not null, -- 작성자
regdate date default sysdate, -- 레코드의 생성 시간
updatedate date default sysdate -- 최종 수정 시간
);
-- 테이블에 primary key로 bno를 지정해줌
alter table tbl_board add constraint pk_board primary key(bno);
-- 더미 데이터
insert into tbl_board(bno, title, content, writer) values(seq_board.nextval, '테트스 제목', '테스트 내용', 'user00');
insert into tbl_board(bno, title, content, writer) values(seq_board.nextval, '테트스 제목', '테스트 내용', 'user00');
insert into tbl_board(bno, title, content, writer) values(seq_board.nextval, '테트스 제목', '테스트 내용', 'user00');
insert into tbl_board(bno, title, content, writer) values(seq_board.nextval, '테트스 제목', '테스트 내용', 'user00');
insert into tbl_board(bno, title, content, writer) values(seq_board.nextval, '테트스 제목', '테스트 내용', 'user00');
select * from tbl_board;
create sequence seq_reply;
create table tbl_reply(
rno number(10, 0),
bno number(10, 0) not null,
reply varchar2(1000) not null,
replyer varchar2(50) not null,
replyDate date default sysdate,
updateDate date default sysdate
);
-- primary key 지정
alter table tbl_reply add constraint pk_reply primary key(rno);
-- forign key 지정
alter table tbl_reply add constraint fk_reply_board foreign key(bno) references tbl_board(bno);
select * from tbl_reply;
-- 특정 게시물에 속한 댓글을 찾는 속도를 높이기위해 인덱스 생성(첫째열 : bno 내림차순, 둘째열 : bno가 같으면 rno 오름차순) 429p.
create index index_reply on tbl_reply(bno desc, rno asc);
insert into tbl_reply(rno, bno, reply, replyer) values(seq_reply.nextval, 3145745, 'kkk', 'user99');
commit;