(오라클) 통합 문제




main
--1.임의의 테이블 스페이스(samtb(논리적이름),damtb.dbf(물리적이름)를 만들기. = > 크기는 1GB
    create tablespace samtb
    datafile 'd:\dbspace\damtb.dbf'
        size 1G;
       

--2.생성된 테이블스페이스의 크기를 2GB로 변경하기.

    ALTER DATABASE DATAFILE 'd:\dbspace\damtb.dbf'
   RESIZE 2G;

--3.테이블 스페이스의 물리적 이름을 변경하기.(damtb.dbf samtb.dbf)



--4.임의의 사용자를 생성하고 생성된 테이블스페이스를 지정하기.

    create user lucky identified by lucky
    default tablespace samtb
    ;

--5.생성된사용자에 대한 권한(connect,resource)을 부여하기.

    grant resource, connect to lucky;
   
--6.생성된 사용자에 대한 퍼블릭 시노님 생성 권한 부여하기.

    grant create public synonym to lucky;

--7.hr 권한에 대한 비밀번호 변경하기. (hr=>hr1234)

    alter user hr identified by  hr1234;
--8.hr이 소유하고 있는 테이블 employee ,departments ,jobs 에 대한 객체 권한(select)을 생성된 자용자에게 부여하기

    grant select on hr.employees to lucky;
    grant select on hr.departments to lucky;
    grant select on hr.jobs to lucky;

 --13. 12의 내용을 담은 allTableView를 만들기.

 grant create view to lucky;

--14. 모든 생성된 객체 및 권한을 삭제할 것 ...


revoke connect,resource from lucky;
revoke select on hr.employees from lucky;
revoke select on hr.departments from lucky;
revoke select on hr.jobs from lucky;
revoke create public synonym from lucky;
revoke create view from lucky;
drop view lucky.allTableView;
drop tablespace samtb;
drop table myemp;
drop table mydepart;
drop table myjobs;
drop public synonym emp;
drop public synonym depart;
drop public synonym jobs;
drop user lucky;


--8.employees테이블을 쉽게 접근할 수 있도록 퍼블릭 시노님을 만들기 (emp,depart,jobs)
    create or replace PUBLIC synonym emp FOR hr.employees;
     create or replace PUBLIC synonym depart FOR hr.departments;
      create or replace PUBLIC synonym jobs FOR hr.jobs;
     
--9. 생성된 사용자는 시노님을 이용하여 myemp,mydepart,myjobs테이블을 만들기

    create table myemp as select * from emp;
    create table mydepart as select * from depart;
    create table myjobs as select * from jobs;



--10. 생성된 사용자는 생성된 my ???테이블에 대하여 제약조건을 부여하기(myemp테이블은 employees와 동일한 제약조건 부여)

--테이블 간의 계층 구조 파악하기
--parent table must be made at first…and the constraint
--myemp mydepart myjobs를 참조해야한다
--mydepart myjobs의 제약조건이 pk로 먼저 변경 되어야한당!

alter table mydepart add constraint mydepart_id primary key(department_id);

alter table myemp add constraint myemp_id_pk primary key(employee_id);
alter table myemp add constraint myemp_email_unique unique(email);
alter table myemp rename constraint SYS_C006998 to myemp_email_notnull;
alter table myemp rename constraint SYS_C007000 to myemp_jobid_notnull;
alter table myemp rename constraint SYS_C006997 to myemp_lastname_notnull;
alter table myemp rename constraint SYS_C006999 to myemp_hiredate_notnull;
alter table myemp add constraint myemp_dept_FK foreign key(department_id)
references mydepart(department_id);
alter table myemp add constraint myemp_manager_FK foreign key(manager_id)
references HR.EMPLOYEES(employee_id);

alter table mydepart rename constraint SYS_C007002 to mydepart_name_nn;
alter table mydepart add constraint mydepart_MNG_FK foreign key(manager_id)
references hr.employees(employee_id);

alter table myjobs add constraint myjobs_id_pk primary key(job_id);
alter table myjobs rename constraint SYS_C007001 to myjobs_title_NN;

hr 계정에서, 외래키를 할 때!
grant REFERENCES on employees to lucky;
grant REFERENCES on jobs to lucky;
grant REFERENCES on departments to lucky;

main 계정에서 depart에 권한을 줄 때
grant resource to lucky;



--11. 생성된 사용자는 myemp테이블의 email컬럼을 인덱스로 만들기.

    create index myemp_email_index on myemp(email);

--12. 생성된 사용자는 3개의 테이블에 대한 모든 항목을 출력하는 문장 만들기 (조인을 이용할 것)
    SELECT emp.*, depart.department_name, depart.location_id, depart_manager_id, jobs.job_title, jobs.max_salary
    FROM emp , depart ,jobs
    WHERE emp.department_id = depart.department_id(+) and jobs.job_id= emp.job_id(+);
   
 --13. 12의 내용을 담은 allTableView를 만들기.

create or replace view allTableView
as
select emp.employee_id, emp.first_name,emp.last_name,emp.email,emp.phone_number,emp.hire_date,emp.job_id,emp.salary,emp.commission_pct,
jobs.job_title, jobs.min_salary, jobs.max_salary,
depart.department_id, depart.department_name, depart.manager_id, depart.location_id
from emp, depart, jobs
where emp.department_id = depart.department_id(+)
and emp.job_id = jobs.job_id(+);

댓글

이 블로그의 인기 게시물

c++ 랜덤 숫자 생성하기 / 컴퓨터 난수 시드 설정

(오라클) View(뷰) + where/order by/like/is/() / in 사용방법 예제

(오라클) Sequence/시퀸스의 활용과 개념