--회원 테이블
create table team_join (
userid varchar2(50) not null primary key, -- 아이디
passwd varchar2(50) not null, -- 비밀번호
age number not null, -- 나이
name varchar2(50) not null, -- 이름
email varchar2(50) not null, -- 이메일
address varchar2(50) not null, -- 주소
zipcode varchar2(50) not null, -- 우편번호
hp varchar2(50) not null, -- 전화번호
gender varchar2(50) not null, -- 성별
point number not null, --포인트
join_date date default sysdate --가입일자
);
select*from team_join;
drop table team_join;
insert into team_join values('admin','1234',12,'관리자','kim@naver.com','서울시 강동구','11111111','1111-111','남',100000,'2019/1/1');
-------------------------------------------------------------------------------
?-- cascade constraints 제약조건까지 모두 삭제
drop table bboard cascade constraints;
--관리자 게시판 테이블
create table bboard (
bno number not null, --게시물번호
title varchar2(200) not null, --제목
content clob, --본문
writer varchar2(50) not null, --작성자
regdate date default sysdate, --작성일자
viewcnt number default 0, --조회수
primary key(bno)
);
----------------------------------------------------------------------------------
insert into bboard (bno,title,content,writer) values
(1,'제목','내용','관리자임');
drop table bboard;
select * from bboard;
----------------------------------------------------------------------------------------
--댓글 테이블
drop table reply cascade constraints;
create table reply (
rno number not null primary key,
bno number default 0,
replytext varchar2(1000) not null,
replyer varchar2(50) not null,
regdate date default sysdate,
updatedate date default sysdate
);
-------------------------------------------------------------------------------------------
--foreign key 제약조건 추가
alter table reply add constraint fk_bboard
foreign key(bno) references bboard(bno);
--시퀀스 생성
drop sequence reply_seq;
create sequence reply_seq
start with 1
increment by 1;
--첨부파일 테이블
drop table attach cascade constraints;
---------------------------------------------------------------------------
create table attach (
fullName varchar2(150) not null, --첨부파일 이름
bno number not null, --board 테이블의 글번호
regdate date default sysdate, --업로드 날짜
primary key(fullName) --uuid적용한 파일이름
);
-----------------------------------------------------------------------------
--bno 컬럼에 foreign key 설정
alter table attach add constraint fk_bboard_attach
foreign key(bno) references bboard(bno);
select bno,writer,title,regdate,viewcnt
from bboard
order by bno desc;
-- writer의 id대신 이름이 나오게 하려면 member테이블과 조인
select bno,title,writer,name,regdate,viewcnt
from bboard b, team_join t
where b.writer=t.userid
order by bno desc;
select * from team_join;
delete from reply;
delete from bboard;
commit;
--페이지 나누기 테스트를 위해 레코드 입력
declare --선언부
i number := 1;
begin --실행부
while i<=100 loop
insert into bboard (bno,title,content,writer)
values
( (select nvl(max(bno)+1,1) from bboard)
,'Amado 공지사항입니다.'||i, '내용'||i, 'admin');
i := i+1; --조건 변경
end loop;
end;
/
select * from bboard;
--레코드 갯수 확인
select count(*) from bboard;
commit;
-- from => where => select => order by 절 순서로 실행됨
-- rownum : 레코드의 출력 순번
select *
from (
select rownum as rn, A.*
from (
select bno,title,writer,name,regdate,viewcnt
from bboard b, team_join t
where b.writer=t.userid
order by bno desc
) A
) where rn between 1 and 10;
--------------페이지 나누기 공식 참조-----------------
11페이지
where rn between A and B
(현재페이지-1) x 페이지당 게시물수 + 1
= (11-1) x 10 + 1 = 101
11페이지
[이전] 11 12 .... 20 [다음]
몇번째 블록
( 현재페이지-1) / 페이지블록단위 + 1
(11-1)/10 + 1 => 2번째 블록 ( 몇페이지 ~ 몇페이지 )
( 현재블록-1) x 블록단위 + 1
(2-1) x 10 + 1 = 11페이지
게시물 991개 / 10개 => 99.1 => 100페이지
100페이지 / 10개 => 페이지블록 10개
--글쓰기를 하기 위한 시퀀스 삭제
drop sequence seq_bboard;
--100번부터 시작하는 시퀀스 생성
create sequence seq_bboard
start with 100
increment by 1;
commit;
-- board에 시퀀스를 추가
create sequence seq_bboard
start with 1
increment by 1;
commit;
--board 테이블에 필드 추가
alter table bboard add show char(1) default 'Y';
desc bboard;
select * from bboard;
select bno,title,writer,name,regdate,viewcnt
,(select count(*) from reply where bno=b.bno) cnt
, show
from bboard b, team_join t
where b.writer=t.userid
and show='Y'
order by bno desc;
update bboard set show='N' where bno=100;--해당게시물 번호로 처리
--위 update문은 실제 데이터가 지워지는건 아니지만 보여지지 않게 처리함.
commit;
update bboard set title='책상제품 교환 공지사항2', content='책상환불해드립니다.' where bno=99;
--------------------------------------------------------------------------
commit;
독학으로 작성한 쿼리문인데
무결성위반? 그거라고 뜨길래 원인을 모르겠어서 올려봐요..
너무어려운데 어디가 문제인지 대충이라도 알 수 있을까요?
사실 잘모르겠어요... 저런식으로 쓰면되나싶어서 기입하면서 한건데
리스트 수정 삭제 목록가기 이 3개 누르니까
### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: insert into bboard (bno,title,content,writer) values (seq_bboard.nextval, ?,?, ?) ### Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (SPRING.SYS_C008066) violated
이런 문장이뜨네요