データベースベース——データ準備

11653 ワード

どんな技術も見たりしないではいられません。プログラミングは特にこのようです。次は2つの表を作成します。社員表と部門表(dept)を挿入して、次の勉強に使います。
--      emp
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)
);

--      dept
CREATE TABLE dept(
  deptno NUMBER(2,0),
  dname VARCHAR2(14 BYTE),
  loc VARCHAR2(13 BYTE)
);

--     
INSERT INTO emp VALUES(7369,'SMITH','CLERK',7902,
                       TO_DATE('1980-12-17','yyyy-mm-dd'),
                       800,NULL,20);
INSERT INTO emp VALUES(7499,'ALLEN','SALSESMAN',7698,
                       TO_DATE('1981-02-20','yyyy-mm-dd'),
                       1600,300,30);
INSERT INTO emp VALUES(7521,'WARD','SALSESMAN',7698,
                       TO_DATE('1981-02-22','yyyy-mm-dd'),
                       1250,500,30);
INSERT INTO emp VALUES(7566,'JONSE','MANAGER',7839,
                       TO_DATE('1981-04-02','yyyy-mm-dd'),
                       2975,NULL,20);
INSERT INTO emp VALUES(7654,'MARTIN','SALSESMAN',7698,
                       TO_DATE('1981-09-28','yyyy-mm-dd'),
                       1250,1400,30);
INSERT INTO emp VALUES(7698,'BLAKE','MANAGER',7839,
                       TO_DATE('1981-05-01','yyyy-mm-dd'),
                       2850,NULL,30);
INSERT INTO emp VALUES(7782,'CLARK','MANAGER',7839,
                       TO_DATE('1981-06-09','yyyy-mm-dd'),
                       2450,NULL,10);
INSERT INTO emp VALUES(7788,'SCOTT','ANALYST',7566,
                       TO_DATE('1987-04-19','yyyy-mm-dd'),
                       3000,NULL,50);
INSERT INTO emp VALUES(7839,'KING','PRESIDENT',NULL,
                       TO_DATE('1981-11-17','yyyy-mm-dd'),
                       5000,NULL,10);
INSERT INTO emp VALUES(7844,'TURNER','SALESMAN',7698,
                       TO_DATE('1981-09-08','yyyy-mm-dd'),
                       1500,0,30);
INSERT INTO emp VALUES(7876,'ADAMS','CLERK',7788,
                       TO_DATE('1987-05-23','yyyy-mm-dd'),
                       1100,NULL,20);       
INSERT INTO emp VALUES(7900,'JAMES','CLERK',7698,
                       TO_DATE('1981-12-03','yyyy-mm-dd'),
                       950,NULL,30);  
INSERT INTO emp VALUES(7902,'FORD','ANALYST',7566,
                       TO_DATE('1987-05-23','yyyy-mm-dd'),
                       3000,NULL,20);  
INSERT INTO emp VALUES(7934,'MILLER','CLERK',7782,
                       TO_DATE('1982-01-23','yyyy-mm-dd'),
                       1300,NULL,10);      

INSERT INTO dept VALUES(10,'ACCOUNTING','NEW YORK');  
INSERT INTO dept VALUES(20,'RESEARCH','DALLAS');
INSERT INTO dept VALUES(30,'SALSE','CHICAGO');
INSERT INTO dept VALUES(40,'OPERATIONS','BOSTON');

COMMIT;

SELECT * FROM emp;
SELECT * FROM dept;