(1) Orcale 초식과 라이브러리 표의 첨삭 수정
6212 단어 데이터베이스 학습 개인 노트
하나.명령 창 들어가기
a. sqlplus---
b. sqlplusw--- -- a
둘.환경 설정 - set 명령
a. set linesize ---
b. set pagesize ---
셋.오류 명령 수정 방법
a. ed---
b. @---
c. , , sql
d. “/”---
넷.사용자 전환 - conn 사용자 이름/암호 [as sysdba]
a. sys as sysdba,
b. --- . (scott.emp)
c. ---show user
오.데이터베이스에 있는 모든 테이블의 이름 가져오기 - select * from tab
데이터베이스 업데이트
a. insert( ),update( , ),delete( )
b. ---create table as select * from ;
c. clear scr;---
d. to_date('2008-08-08','yyyy-mm-dd')
e. delete , ---delete from ;
f. drop table ;---
g. select job,count(empno)
from emp where job
in
(select job from emp group by job having min(sal) > 1500)
--- emp job 1500
group by job;
--- emp in ,
양식 작성 및 삭제
a.
i. varchar(varchar2)--- , 225
ii. number---number(n)--- , n, int,number(m,n)--- , n, m-n, float
iii. date---
iv. clob--- , , 4G
v. blob--- , , 4G
b.
i. create table ( [default ],……)
ii. ---create table as ( ), , ,
c.
i. ---alter table add( default ,……)
ii. ---alter table modify( default ,……)--- , ,
d.
rename , oracle
rename to
e.
drop table ---
, ,
truncate table ;
제약조건의 분류 및 사용 - 제약조건을 사용하여 데이터베이스 테이블의 데이터 무결성을 보장
a.
i. --- ,
ii. --- , ,
iii. ---
iv. ---
v. ---
b. ---primary key--- , constraint ---constraint person_pid_pk primary key(pid)
c. ---not null---
d. ---unique--- , --- constraint ---constraint person_name_uk unique(name)
e. ---check--- , ---check(age between 0 and 150)--- , constraint ---constraint person_age_ck check(age between 0 and 150)
f. ---foreign key--- ,
i. - --- , ---constraint person_book_pid_fk foreign key(pid)--- ( ) references person(pid)---
ii.
iii. , --- ---drop table book cascade constraint
iv. , ---constraint person_book_pid_fk foreign key(pid) references person(pid) on delete cascade
g.
i. ---alter table add constraint ( )
ii. --- ---alter table drop constraint
h. rownum--- / ---
i. select rownum ,ename from emp;--- *
ii. select rownum, ename from emp where rownum <= 5;
iii. ---
---select * from (select rownum m,empno,ename from emp where rownum<=10) temp where temp.m>5;
데이터 조회
단순 조회, 한정 조회
a.
i. ---- 、 ,
ii. ---select [distinct] (* or or ) from ;
b. distinct
i. select distinct from ;
ii. : , , , ( ) 。
c.
i. orcale , “||”
ii. , “‘’”
iii. :select ' :' || empno || ' , :' ||ename|| ', :' || job from emp;
iv.
d. ---where
i. (null)---where is not null
ii. and
iii. :or ---
iv. :not XXX---XXX
v. :where between and ----
vi. ---where between '1-1 -81' and '31-12 -81'--- ,
vii. : orcale ,
viii. --- in --- in ( 1, 2, 3……) not in ()
---in
ix. : in , ,
x. like --- “‘’”
1) “%”:
2) “_”:
xi. :"<>" , "!="
e. ---order by--- sql from---where---group by---having---select--order by
i. , desc
ii. --- “,” , , , 。
다중 테이블 조회
a. : ,
select e.ename,e.sal,d.dname,s.grade,m.ename,m.sal,ms.grade from emp e,emp m,salgrade s,dept d,salgrade ms where e.deptno=d.deptno and e.sal between s.losal and s.hisal and e.mgr=m.empno and m.sal between ms.losal and ms.hisal
select e.ename,e.sal,d.dname,decode(s.grade,1,' ',2,' ',3,' ',4,' ',5,' '),
m.ename,m.sal,decode(ms.grade,1,' ',2,' ',3,' ',4,' ',5,' ')
from emp e,emp m,salgrade s,dept d,salgrade ms
where e.deptno=d.deptno and e.sal between s.losal and s.hisal and e.mgr=m.empno and m.sal between ms.losal and ms.hisal
b. 、
i. select e.empno,e.ename,d.deptno,d.dname,d.loc from emp e,dept d where e.deptno(+)=d.deptno;
ii. (+) ,
iii. (+) = ,(+) = ,
e. Sql1999( )
i. cross join--- ---
ii. natural join--- ---
iii. using : ---select * from emp e join dept d using(deptno) where deptno =30;
iv. on :
하위 질의
한 검색어의 내부에 다른 검색어를 포함하다
a. “()”
b.
i. ---
ii. ---
iii. ---
c. in,any,all
i. in--- --- , , in ---select * from emp where sal in(select min(sal) from emp group by deptno);--- emp deptno , sal
ii. any
1) =any
2) >any --- ,
3) all---
2)