본문 바로가기
IT/ORACLE

[ORACLE] 오라클 샘플 데이터 생성.

by 쫄보에서고수까지 2020. 6. 22.
반응형

CREATE, ALTER, DROP

SELECT, DELETE, UPDATE, INSERT 강의를 보고 오시면 내용을 이해하실때 도움 됩니다.


기초 테이블을 가지고 놀기 전에 샘플 데이터 스크립트를 실행 합니다.


/*

    사원 Table 삭제

*/

DROP TABLE EMP;

/*

    부서 Table 삭제

*/

DROP TABLE DEPT;



/*

    Create DEPT table which will be the parent table of the EMP table.

*/


create table dept( 

  deptno     number(2,0), 

  dname      varchar2(14), 

  loc        varchar2(13), 

  constraint pk_dept primary key (deptno) 

);


/*

    Create the EMP table which has a foreign key reference to the DEPT table.

    The foreign key will require that the DEPTNO in the EMP table exist in the DEPTNO column in the DEPT table.

*/

create table emp( 

  empno    number(4,0), 

  ename    varchar2(10), 

  job      varchar2(9), 

  mgr      number(4,0), 

  hiredate date, 

  sal      number(7,2), 

  comm     number(7,2), 

  deptno   number(2,0), 

  constraint pk_emp primary key (empno), 

  constraint fk_deptno foreign key (deptno) references dept (deptno) 

);


/*

    Insert row into DEPT table using named columns.

*/

insert into DEPT (DEPTNO, DNAME, LOC) values(10, 'ACCOUNTING', 'NEW YORK');


/*

    Insert a row into DEPT table by column position.

*/

insert into dept values(20, 'RESEARCH', 'DALLAS');


insert into dept values(30, 'SALES', 'CHICAGO');


insert into dept values(40, 'OPERATIONS', 'BOSTON');



/*

    Insert EMP row, using TO_DATE function to cast string literal into an oracle DATE format.

*/

/*

    Insert EMP row, using TO_DATE function to cast string literal into an oracle DATE format.

*/

insert into emp values(  7839, 'KING', 'PRESIDENT', null,   '1981-11-17',   5000, null, 10 );


insert into emp values(  7698, 'BLAKE', 'MANAGER', 7839,   '1981-05-01',   2850, null, 30 );


insert into emp values(  7782, 'CLARK', 'MANAGER', 7839,   '1981-06-09',   2450, null, 10 );


insert into emp values(  7566, 'JONES', 'MANAGER', 7839,   '1981-04-02',   2975, null, 20 );


insert into emp values(  7788, 'SCOTT', 'ANALYST', 7566,   '1987-04-19',  3000, null, 20 );


insert into emp values(  7902, 'FORD', 'ANALYST', 7566,   '1981-12-03',   3000, null, 20 );


insert into emp values(  7369, 'SMITH', 'CLERK', 7902,   '1980-12-17',   800, null, 20 );


insert into emp values(  7499, 'ALLEN', 'SALESMAN', 7698,   '1981-02-20',   1600, 300, 30 );


insert into emp values(  7521, 'WARD', 'SALESMAN', 7698,   '1981-02-22',   1250, 500, 30 );


insert into emp values(  7654, 'MARTIN', 'SALESMAN', 7698,   '1981-09-28',   1250, 1400, 30 );


insert into emp values(  7844, 'TURNER', 'SALESMAN', 7698,   '1981-09-08',   1500, 0, 30 );


insert into emp values(  7876, 'ADAMS', 'CLERK', 7788,   '1987-05-23',  1100, null, 20 );


insert into emp values(  7900, 'JAMES', 'CLERK', 7698,   '1981-12-03',   950, null, 30 );


insert into emp values(  7934, 'MILLER', 'CLERK', 7782,   '1982-01-23',   1300, null, 10 );




EMP,DEPT 라는 테이블을 DROP 먼저 하고 CREATE 해서 중복을 피하고 데이터 INSERT 를 실행하게 됩니다.



스크립트 실행 이 후

- SELECT * FROM EMP 의 결과 -


- SELECT * FROM DEPT 의 결과 -




조회한 결과가 다음과 같다면 성공한 걸 알 수 있습니다.


위의 결과들로 실무적으로 쓸 수 있도록 조건과 추가,변경,삭제 등 해볼 예정입니다.

이 내용은 추후 직접 웹개발을 통해 추가,변경,삭제,조회 등을 해볼 예정입니다. 


ex) 홈쇼핑 회원가입 및 회원정보 변경 




반응형
LIST

댓글