1. ホーム
  2. データベース
  3. 神託

オラクルデータベースに付属するすべてのテーブル構造を説明する(sqlコード)

2022-01-07 20:15:08

I. tb_emp (従業員テーブル)

1. テーブルの構築

CREATE TABLE "TEST". "TB_EMP" (	
	"EMPNO" NUMBER(4,0) PRIMARY KEY NOT NULL, 
	"ENAME" VARCHAR2(10), 
	"JOB" VARCHAR2(9), 
	"MGR" NUMBER(4,0), 
	"HIREDATE" DATE, 
	"SAL" NUMBER(7,2), 
	"COMM" NUMBER(7,2), 
	"DEPTNO" NUMBER(2,0)
);
COMMENT ON COLUMN "TEST". "TB_EMP". "EMPNO" IS 'Employee Number';
COMMENT ON COLUMN "TEST". "TB_EMP". "ENAME" IS 'Name';
COMMENT ON COLUMN "TEST". "TB_EMP". "JOB" IS 'Position';
COMMENT ON COLUMN "TEST". "TB_EMP". "MGR" IS 'Leader Number';
COMMENT ON COLUMN "TEST". "TB_EMP". "HIREDATE" IS 'Entry Time';
COMMENT ON COLUMN "TEST". "TB_EMP". "SAL" IS 'Base Salary';
COMMENT ON COLUMN "TEST". "TB_EMP". "COMM" IS 'Bonus';
COMMENT ON COLUMN "TEST". "TB_EMP". "DEPTNO" IS 'Department Number';
COMMENT ON TABLE "TEST". "TB_EMP" IS 'Employee Table';

2. データのインポート

INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7369,'Smith','Storekeeper',7902,TIMESTAMP '1980-12-17 00:00: 00.000000',800,NULL,20);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7499,'Allen','Salesman',7698,TIMESTAMP '1981-02-20 00:00: 00.000000',1600,300,30);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7521,'Ward','Salesman',7698,TIMESTAMP '1981-02-22 00:00: 00.000000',1250,500,30);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7566,'Jones','Manager',7839,TIMESTAMP '1981-04-02 00:00: 00.000000',2975,NULL,20);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7654,'Martin','Salesman',7698,TIMESTAMP '1981-09-28 00:00: 00.000000',1250,1400,30);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7698,'Blake','Manager',7839,TIMESTAMP '1981-05-01 00:00: 00.000000',2850,NULL,30);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7782,'Clark','Manager',7839,TIMESTAMP '1981-06-09 00:00: 00.000000',2450,NULL,10);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7788,'Scott','Analyst',7566,TIMESTAMP '1987-04-19 00:00: 00.000000',3000,NULL,20);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7839,'King','President',NULL,TIMESTAMP '1981-11-17 00:00: 00.000000',5000,NULL,10);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7844,'Turner','Salesman',7698,TIMESTAMP '1981-09-08 00:00: 00.000000',1500,0,30);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7876,'Adams','Storekeeper',7788,TIMESTAMP '1987-05-23 00:00: 00.000000',1100,NULL,20);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7900,'James','Storekeeper',7698,TIMESTAMP '1981-12-03 00:00: 00.000000',950,NULL,30);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7902,'Ford','Analyst',7566,TIMESTAMP '1981-12-03 00:00: 00.000000',3000,NULL,20);
INSERT INTO "TB_EMP" (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES (7934,'Miller','Storekeeper',7782,TIMESTAMP '1982-01-23 00:00: 00.000000',1300,NULL,10);

3. ルックアップテーブル

SELECT * FROM "TEST". "TB_EMP"

II. tb_dept(部門テーブル)

1. テーブルの構築

CREATE TABLE "TEST". "TB_DEPT" (	
	"DEPTNO" NUMBER(2,0) PRIMARY KEY NOT NULL,  
	"DNAME" VARCHAR2(14), 
	"LOC" VARCHAR2(13)
 );
COMMENT ON COLUMN "TEST". "TB_DEPT". "DEPTNO" IS 'Department Number';
COMMENT ON COLUMN "TEST". "TB_DEPT". "DNAME" IS 'Department Name';
COMMENT ON COLUMN "TEST". "TB_DEPT". "LOC" IS 'Department Location';
COMMENT ON TABLE "TEST". "TB_DEPT" IS 'Department Table';

2. データのインポート

INSERT INTO "TB_DEPT" (DEPTNO,DNAME,LOC) VALUES (10,'Accounting','New York');
INSERT INTO "TB_DEPT" (DEPTNO,DNAME,LOC) VALUES (20,'Research','Dallas');
INSERT INTO "TB_DEPT" (DEPTNO,DNAME,LOC) VALUES (30,'Sales','Chicago');
INSERT INTO "TB_DEPT" (DEPTNO,DNAME,LOC) VALUES (40,'Operations','Boston');

3. ルックアップテーブル

SELECT * FROM "TEST". "TB_DEPT";

三、tb_bonus(ボーナステーブル)

1、テーブルを作る

CREATE TABLE TEST."TB_BONUS" (	
"ENAME" VARCHAR2(10), 
"JOB" VARCHAR2(9), 
"SAL" NUMBER, 
"COMM" NUMBER
); 
COMMENT ON COLUMN "TEST". "TB_BONUS". "ENAME" IS 'Name';
COMMENT ON COLUMN "TEST". "TB_BONUS". "JOB" IS 'Position';
COMMENT ON COLUMN "TEST". "TB_BONUS". "SAL" IS 'Base Salary'; 
COMMENT ON COLUMN "TEST". "TB_BONUS". "COMM" IS 'Bonus';
COMMENT ON TABLE "TEST". "TB_BONUS" IS 'Bonus Table';

2. データのインポート

3. ルックアップテーブル

IV. tb_salgrade(給与体系)

1. テーブルの構築

CREATE TABLE "TEST". "TB_SALGRADE" (
	"GRADE" NUMBER, 
	"LOSAL" NUMBER, 
	"HISAL" NUMBER
);
COMMENT ON COLUMN "TEST". "TB_SALGRADE". "GRADE" IS 'Salary Grade';
COMMENT ON COLUMN "TEST". "TB_SALGRADE". "LOSAL" IS 'Minimum Wage';
COMMENT ON COLUMN "TEST". "TB_SALGRADE". "HISAL" IS 'Highest Wage';
COMMENT ON TABLE "TEST". "TB_SALGRADE" IS 'Salary Scale Table';

2. データのインポート

INSERT INTO TEST.TB_SALGRADE (GRADE,LOSAL,HISAL) VALUES (1,700,1200);
INSERT INTO TEST.TB_SALGRADE (GRADE,LOSAL,HISAL) VALUES (2,1201,1400);
INSERT INTO TEST.TB_SALGRADE (GRADE,LOSAL,HISAL) VALUES (3,1401,2000);
INSERT INTO TEST.TB_SALGRADE (GRADE,LOSAL,HISAL) VALUES (4,2001,3000);
INSERT INTO TEST.TB_SALGRADE (GRADE,LOSAL,HISAL) VALUES (5,3001,9999);

3. テーブルを調べる

SELECT * FROM TEST.TB_SALGRADE;

 V. tb_users(ユーザーテーブル)

1. テーブルの構築

CREATE TABLE "TEST". "TB_USERS" (	
	"ID" VARCHAR2(10) PRIMARY KEY NOT NULL,  
	"USERNAME" VARCHAR2(64), 
	"PASSWORD" VARCHAR2(64),
	"AGE" NUMBER(3,0),
	"SEX" VARCHAR2(1)
);
 
COMMENT ON COLUMN "TEST". "TB_USERS". "ID" IS 'user unique id';
COMMENT ON COLUMN "TEST". "TB_USERS". "USERNAME" IS 'username';
COMMENT ON COLUMN "TEST". "TB_USERS". "PASSWORD" IS 'Password';
COMMENT ON COLUMN "TEST". "TB_USERS". "AGE" IS 'Age';
COMMENT ON COLUMN "TEST". "TB_USERS". "SEX" IS 'Gender';
COMMENT ON TABLE "TEST". "TB_USERS" IS 'User Table';

2. データのインポート

INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('1','Smith','123456',23,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('2','Allen','123456',18,'0');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('3','Ward','123456',28,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('4','Jones','123456',19,'0');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('5','Martin','123456',25,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('6','Blake','123456',27,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('7','Clark','123456',29,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('8','Scott','123456',32,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('9','King','123456',90,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('10','Turner','123456',52,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('11','Adams','123456',46,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('12','James','123456',34,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('13','Ford','123456',65,'1');
INSERT INTO "TB_USERS" (ID,USERNAME,PASSWORD,AGE,SEX) VALUES ('14','Miller','123456',75,'1');

3. ルックアップテーブル

select * from "TEST". "TB_USERS";

 VI. tb_saldetail(給与詳細テーブル)

1. テーブルの構築

CREATE TABLE "UCLM". "TB_SALDETAIL" (
    "SALNO" NUMBER(4,0) PRIMARY KEY NOT NULL, 
    "ENAME" VARCHAR2(10),
    "SALYEAR" VARCHAR2(10),
    "SALMONTH" VARCHAR2(4),
    "SAL" NUMBER(7,2), 
    "COMM" NUMBER(7,2), 
    "EMPNO" NUMBER(4,0) 
);
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "SALNO" IS 'Payroll Number';
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "ENAME" IS 'Name';
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "SALYEAR" IS 'Year of payroll';
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "SALMONTH" IS 'Payroll Month';
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "SAL" IS 'Base Salary';
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "COMM" IS 'Bonus';
COMMENT ON COLUMN "UCLM". "TB_SALDETAIL". "EMPNO" IS 'Employee Number';
COMMENT ON TABLE "UCLM". "TB_SALDETAIL" IS 'Payroll Detail Table';

2. データのインポート

INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(1, 'Smith', '2020', '01', 800, 0, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(2, 'Smith', '2020', '02', 801.14, 300, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(3, 'Smith', '2020', '03', 804.21, null, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(4, 'Smith', '2020', '04', 806.41, null, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(5, 'Smith', '2020', '05', 800.55, 100, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(6, 'Smith', '2020', '06', 806.14, 200, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(7, 'Smith', '2020', '07', 800.55, null, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(8, 'Smith', '2020', '08', 806.84, null, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(9, 'Smith', '2020', '09', 800.77, null, 7369);
INSERT INTO TEST.TB_SALDETAIL (SALNO, ENAME, SALYEAR, SALMONTH, SAL, COMM, EMPNO) VALUES(10, 'Smith', '2020', '10', 806.85, null, 7369);
INSERT INTO TEST.TB_SALDETAIL (