0% found this document useful (0 votes)
28 views

INF313 - Class Exercise

The document provides scripts to create tables for a simple HR database in Oracle. It includes scripts to create tables for departments, employees, salary grades, and timekeeping records. It also provides scripts to insert sample data into these tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

INF313 - Class Exercise

The document provides scripts to create tables for a simple HR database in Oracle. It includes scripts to create tables for departments, employees, salary grades, and timekeeping records. It also provides scripts to insert sample data into these tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Class Exercise

1- Introduction
Depending on the database type you are familiar with, you can copy its scripts to create Simple hr
for that database. We support some database types:

 Oracle
 MySQL
 SQL Server

2. Oracle - Creation Script


 ORACLE SCRIPT:

?
1 create table DEPARTMENT (
2 DEPT_ID number(10,0) not null,
3 DEPT_NAME varchar2(255 char) not null,
4 DEPT_NO varchar2(20 char) not null unique,
5 LOCATION varchar2(255 char),
6 primary key (DEPT_ID)
7 );
8
9 create table EMPLOYEE (
EMP_ID number(19,0) not null,
10
EMP_NAME varchar2(50 char) not null,
11
EMP_NO varchar2(20 char) not null unique,
12
HIRE_DATE date not null,
13
IMAGE blob,
14
JOB varchar2(30 char) not null,
15
SALARY float not null,
16
DEPT_ID number(10,0) not null,
17 MNG_ID number(19,0),
18 primary key (EMP_ID)
19 );
20
21 create table SALARY_GRADE (
22 GRADE number(10,0) not null,
23 HIGH_SALARY float not null,
24 LOW_SALARY float not null,
25 primary key (GRADE)
26 );
27
28 create table TIMEKEEPER (
29 Timekeeper_Id varchar2(36 char) not null,
30 Date_Time timestamp not null,
31 In_Out char(1 char) not null,

1
32 EMP_ID number(19,0) not null,
33 primary key (Timekeeper_Id)
34 );
35
36 alter table EMPLOYEE
37 add constraint FK75C8D6AE269A3C9
38 foreign key (DEPT_ID)
39 references DEPARTMENT;
40
41 alter table EMPLOYEE
42 add constraint FK75C8D6AE6106A42
43 foreign key (EMP_ID)
44 references EMPLOYEE;
45
46 alter table EMPLOYEE
47 add constraint FK75C8D6AE13C12F64
48 foreign key (MNG_ID)
49 references EMPLOYEE;
50
51 alter table TIMEKEEPER
52 add constraint FK744D9BFF6106A42
53 foreign key (EMP_ID)
54 references EMPLOYEE;
55

 INSERT DATA (ORACLE)

?
1 insert into Department (DEPT_ID, DEPT_NAME, DEPT_NO, LOCATION)
2 values (10, 'ACCOUNTING', 'D10', 'NEW YORK');
3
4 insert into Department (DEPT_ID, DEPT_NAME, DEPT_NO, LOCATION)
5 values (20, 'RESEARCH', 'D20', 'DALLAS');
6
7 insert into Department (DEPT_ID, DEPT_NAME, DEPT_NO, LOCATION)
8 values (30, 'SALES', 'D30', 'CHICAGO');
9
10 insert into Department (DEPT_ID, DEPT_NAME, DEPT_NO, LOCATION)
11 values (40, 'OPERATIONS', 'D40', 'BOSTON');
12
13 -------------------------------------------------------------
14 ------------------------------------
15
16
17 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
18 JOB, SALARY, DEPT_ID, MNG_ID)
19 values (7839, 'KING', 'E7839', to_date('17-11-1981', 'dd-mm-
20 yyyy'), 'PRESIDENT', 5000, 10, null);

2
21
22 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
23 JOB, SALARY, DEPT_ID, MNG_ID)
24 values (7566, 'JONES', 'E7566', to_date('02-04-1981', 'dd-mm-
25 yyyy'), 'MANAGER', 2975, 20, 7839);
26
27 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
28 JOB, SALARY, DEPT_ID, MNG_ID)
29 values (7902, 'FORD', 'E7902', to_date('03-12-1981', 'dd-mm-
30 yyyy'), 'ANALYST', 3000, 20, 7566);
31
32 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
33 JOB, SALARY, DEPT_ID, MNG_ID)
34 values (7369, 'SMITH', 'E7369', to_date('17-12-1980', 'dd-mm-
35 yyyy'), 'CLERK', 800, 20, 7902);
36
37 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
38 JOB, SALARY, DEPT_ID, MNG_ID)
39 values (7698, 'BLAKE', 'E7698', to_date('01-05-1981', 'dd-mm-
40 yyyy'), 'MANAGER', 2850, 30, 7839);
41
42 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
43 JOB, SALARY, DEPT_ID, MNG_ID)
44 values (7499, 'ALLEN', 'E7499', to_date('20-02-1981', 'dd-mm-
45 yyyy'), 'SALESMAN', 1600, 30, 7698);
46
47 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
48 JOB, SALARY, DEPT_ID, MNG_ID)
49 values (7521, 'WARD', 'E7521', to_date('22-02-1981', 'dd-mm-
50 yyyy'), 'SALESMAN', 1250, 30, 7698);
51
52 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
53 JOB, SALARY, DEPT_ID, MNG_ID)
54 values (7654, 'MARTIN', 'E7654', to_date('28-09-1981', 'dd-mm-
55 yyyy'), 'SALESMAN', 1250, 30, 7698);
56
57 insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
58 JOB, SALARY, DEPT_ID, MNG_ID)
59 values (7782, 'CLARK', 'E7782', to_date('09-06-1981', 'dd-mm-
60 yyyy'), 'MANAGER', 2450, 30, 7839);
61
insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,
JOB, SALARY, DEPT_ID, MNG_ID)
values (7788, 'SCOTT', 'E7788', to_date('19-04-1987', 'dd-mm-
yyyy'), 'ANALYST', 3000, 20, 7566);

insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,


JOB, SALARY, DEPT_ID, MNG_ID)

3
values (7844, 'TURNER', 'E7844', to_date('08-09-1981', 'dd-mm-
yyyy'), 'SALESMAN', 1500, 30, 7698);

insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,


JOB, SALARY, DEPT_ID, MNG_ID)
values (7876, 'ADAMS', 'E7876', to_date('23-05-1987', 'dd-mm-
yyyy'), 'CLERK', 1100, 20, 7698);

insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,


JOB, SALARY, DEPT_ID, MNG_ID)
values (7900, 'ADAMS', 'E7900', to_date('03-12-1981', 'dd-mm-
yyyy'), 'CLERK', 950, 30, 7698);

insert into Employee (EMP_ID, EMP_NAME, EMP_NO, HIRE_DATE,


JOB, SALARY, DEPT_ID, MNG_ID)
values (7934, 'MILLER', 'E7934', to_date('23-01-1982', 'dd-mm-
yyyy'), 'CLERK', 1300, 10, 7698);

-------------------------------------------------------------
------------------------------------

insert into Salary_Grade (GRADE, HIGH_SALARY, LOW_SALARY)


values (1, 9999, 3001);

You might also like