NCS/SQL 활용

오브젝트 생성 스크립트 얻기

장성한군사 2019. 11. 20. 12:03

** 오브젝트 스크립트 얻기

sqlplus hr/hr

 

set pagesize 0
set long 40000
select dbms_metadata.get_ddl('TABLE','EMPLOYEES','HR') from dual;

 

** 스크립트를 편집하여 새로운 테이블 만들기

CREATE TABLE "HR"."EMP"
   ( "EMPLOYEE_ID" NUMBER(6,0),
"FIRST_NAME" VARCHAR2(20),
"LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN1" NOT NULL ENABLE,
"EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN1" NOT NULL ENABLE,
"PHONE_NUMBER" VARCHAR2(20),
"HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN1" NOT NULL ENABLE,
"JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN1" NOT NULL ENABLE,
"SALARY" NUMBER(8,2),
"COMMISSION_PCT" NUMBER(2,2),
"MANAGER_ID" NUMBER(6,0),
"DEPARTMENT_ID" NUMBER(4,0),
 CONSTRAINT "EMP_SALARY_MIN1" CHECK (salary > 0),
 CONSTRAINT "EMP_EMAIL_UK1" UNIQUE ("EMAIL"),
 CONSTRAINT "EMP_EMP_ID_PK1" PRIMARY KEY ("EMPLOYEE_ID"),
 CONSTRAINT "EMP_DEPT_FK1" FOREIGN KEY ("DEPARTMENT_ID") REFERENCES "HR"."DEPARTMENTS" ("DEPARTMENT_ID"),
 CONSTRAINT "EMP_JOB_FK1" FOREIGN KEY ("JOB_ID") REFERENCES "HR"."JOBS" ("JOB_ID"),
 CONSTRAINT "EMP_MANAGER_FK1" FOREIGN KEY ("MANAGER_ID") REFERENCES "HR"."EMPLOYEES" ("EMPLOYEE_ID")
);

** 테이블 확인 하기
select table_name from user_tables;