
인덱스: 장점: 검색속도 빨라짐
단점: 데이터가 어디에 있는지 찾아서 번그럽다.
-데이터 변경이 자주 발생하면 인덱스의 내요 함깨 서정해야하므로 송능이 저하됨
-추가 공간 필요
-시간이 걸림
생성: create index 인덱스명
on 테이즐명(컬럼명)
삭제: drop index 인덱스명;
조회:
--emp, dept 인덱스 확인
desc user_indexes;
--데이터 사전 구조 확인
desc user_indexes;
desc user_ind_columns;
--emp, dept 인덱스 확인
select index_name, table_name, column_name
from user_ind_columns
where table_name in ('DEPT');
--emp_copy의 name필드에 인덱스 생성
--emp_copy생성
--emp의 기본키를 복사되지 않는다.
create table emp_copy
as select * from emp;
--확인
select * from emp_copy;
--기본키가 없으니
insert into emp_copy
select * from emp;
select * from emp_copy;
--안됨--> 기본키 제약조건(unique constraint)
insert into emp
select * from emp_copy;
--외래키도 마찬가짐
--타이머 설정
set timing on
show timing;
--
select ename
from emp_copy;
--ename에 인덱스 설정
create index emp_copy_index
on emp_copy(ename);
select ename
from emp_copy;
--인덱스 확인
select table_name, index_name, column_name
from user_ind_columns
where table_name in ('EMP_COPY');
--기본키나 유일한 갖ㅅ을 갖는 칼럼에 대해 생성하는 인덱스
--[실습] 고유 인덱스와 비고유 인덱스를 비교, 생성
create unique index emp_job_index
on emp_copy(job);
--> 에러:중복 데이터에 고유 인덱스 지정불가 >> cannot CREATE UNIQUE INDEX; duplicate keys found
--job칼럼에 비고유 인덱스 지정
create index emp_copy_job_index
on emp_copy(job);
--dept_copy 테이블 생성
create table dept_copy
as select * from dept;
--
create index dept_copy_deptno_dname_index
on dept_copy(deptno,dname);
--인덱스 확인 명령
select index_name, table_name, column_name
from user_ind_columns
where table_name in ('DEPT_COPY','EMP_COPY');
--부서이름(dname)으로 인덱스를 생성(고유)
create unique index dept_dname_index
on dept_copy(dname);
-- [실습] emp_copy 테이블에서 sal 칼럼에 sal*12로 인덱스를 설정
--인텍스 생성
create index emp_copy_sal_index
on emp_copy(sal*12);
--연봉이 25000이상인 사원의 정보를 검색
select
from emp_copy
where sal12>25000;
--index drop
drop index cept_copy_deptno_dname_index;