2016년 1월 6일 수요일

오라클버전 P163 tbl_board 테이블 생성 SQL



create table tbl_board (
  bno number,
  title varchar2(200) not null,
  content varchar2(4000) not null,
  writer varchar2(50) not null,
  regdate date default sysdate,
  viewcnt number default 0
);

--Primary key 추가 
alter table tbl_board add constraint pk_board
primary key(bno);

-- 시퀀스 추가 

create sequence seq_board;


P164 새로운 게시물의 등록에 사용하는 SQL 

새로운 게시물의 추가 
insert into tbl_board (bno, title,content,writer)
values (seq_board.nextval,'제목','내용','user00');


게시물의 수정 
update tbl_board set title= '수정된 제목',content = '수정된 내용', writer='user01'
where bno = 1;


게시물의 삭제 
delete tbl_board where bno = 1;


테이블의 자가 복사를 이용한 많은 양의 데이터 넣는 SQL 
여러번 실행하면 현재 테이블의 기하급수적인 데이터가 생성 

insert into tbl_board (bno, title,content,writer)
(select seq_board.nextval, title, content, writer from tbl_board);



MySQL과 달리 오라클은 기본이 Auto Commit이 아니므로 반드시 작업후 커밋을 할것 
commit;

댓글 없음:

댓글 쓰기