SchemaToDoc Enterprise Edition - hr
Note: The Type column includes the maximum size for character fields and the precision/scale (if they have been set) for Number fields.
Table of Contents
All Tables (Tables)........................................................................................................................................ 2
COUNTRIES........................................................................................................................................... 2
DEPARTMENTS..................................................................................................................................... 2
EMPLOYEES.......................................................................................................................................... 3
JOBS........................................................................................................................................................ 3
JOB_HISTORY....................................................................................................................................... 3
LOCATIONS.......................................................................................................................................... 3
REGIONS................................................................................................................................................ 3
All Views (Views)......................................................................................................................................... 3
EMP_DETAILS_VIEW........................................................................................................................... 3
All Stored Procedures (Stored Procedures)................................................................................................... 3
ADD_JOB_HISTORY............................................................................................................................. 3
SECURE_DML........................................................................................................................................ 3
country table. Contains 25 rows. References with locations table.
Primary Key(s): COUNTRY_ID
Field | Type | Nulls? | Comments |
COUNTRY_ID | CHAR (2) | No | Primary key of countries table. |
COUNTRY_NAME | VARCHAR2 (40) | Yes | Country name |
REGION_ID | NUMBER | Yes | Region ID for the country. Foreign key to region_id column in the departments table. |
Index Name | Type | Unique | Fields |
COUNTRY_C_ID_PK | IOT - TOP | Yes | COUNTRY_ID |
No Check Constraints
Internal Foreign Key Constraint | Affected Field | Source Schema | Source Table |
COUNTR_REG_FK | REGION_ID | HR | REGIONS |
Primary Key as Foreign Key Constraint | Affected Schema | Affected Table | Affected Field |
LOC_C_ID_FK | HR | LOCATIONS | COUNTRY_ID |
No Enabled Triggers
Departments table that shows details of departments where employees
work. Contains 27 rows; references with locations, employees, and job_history tables.
Primary Key(s): DEPARTMENT_ID
Field | Type | Nulls? | Comments |
DEPARTMENT_ID | NUMBER (4) | No | Primary key column of departments table. |
DEPARTMENT_NAME | VARCHAR2 (30) | No | A not null column that shows name of a department. Administration, Marketing, Purchasing, Human Resources, Shipping, IT, Executive, Public Relations, Sales, Finance, and Accounting. |
MANAGER_ID | NUMBER (6) | Yes | Manager_id of a department. Foreign key to employee_id column of employees table. The manager_id column of the employee table references this column. |
LOCATION_ID | NUMBER (4) | Yes | Location id where a department is located. Foreign key to location_id column of locations table. |
Index Name | Type | Unique | Fields |
DEPT_ID_PK | NORMAL | Yes | DEPARTMENT_ID |
DEPT_LOCATION_IX | NORMAL | No | LOCATION_ID |
No Check Constraints
Internal Foreign Key Constraint | Affected Field | Source Schema | Source Table |
DEPT_LOC_FK | LOCATION_ID | HR | LOCATIONS |
DEPT_MGR_FK | MANAGER_ID | HR | EMPLOYEES |
Primary Key as Foreign Key Constraint | Affected Schema | Affected Table | Affected Field |
EMP_DEPT_FK | HR | EMPLOYEES | DEPARTMENT_ID |
JHIST_DEPT_FK | HR | JOB_HISTORY | DEPARTMENT_ID |
No Enabled Triggers
employees table. Contains 107 rows. References with departments,
jobs, job_history tables. Contains a self reference.
Primary Key(s): EMPLOYEE_ID
Field | Type | Nulls? | Comments |
EMPLOYEE_ID | NUMBER (6) | No | Primary key of employees table. |
FIRST_NAME | NVARCHAR2 (20) | Yes | First name of the employee. A not null column. |
LAST_NAME | VARCHAR2 (25) | No | Last name of the employee. A not null column. |
VARCHAR2 (25) | No | Email id of the employee | |
PHONE_NUMBER | VARCHAR2 (20) | Yes | Phone number of the employee; includes country code and area code |
HIRE_DATE | DATE | No | Date when the employee started on this job. A not null column. |
JOB_ID | VARCHAR2 (10) | No | Current job of the employee; foreign key to job_id column of the jobs table. A not null column. |
SALARY | NUMBER (8, 2) | Yes | Monthly salary of the employee. Must be greater than zero (enforced by constraint emp_salary_min) |
COMMISSION_PCT | NUMBER (2, 2) | Yes | Commission percentage of the employee; Only employees in sales department elgible for commission percentage |
MANAGER_ID | NUMBER (6) | Yes | Manager id of the employee; has same domain as manager_id in departments table. Foreign key to employee_id column of employees table. (useful for reflexive joins and CONNECT BY query) |
DEPARTMENT_ID | NUMBER (4) | Yes | Department id where employee works; foreign key to department_id column of the departments table |
Index Name | Type | Unique | Fields |
EMP_DEPARTMENT_IX | NORMAL | No | DEPARTMENT_ID |
EMP_EMAIL_UK | NORMAL | Yes | |
EMP_EMP_ID_PK | NORMAL | Yes | EMPLOYEE_ID |
EMP_JOB_IX | NORMAL | No | JOB_ID |
EMP_MANAGER_IX | NORMAL | No | MANAGER_ID |
EMP_NAME_IX | NORMAL | No | LAST_NAME, FIRST_NAME |
Check Constraint Name | Text |
EMP_SALARY_MIN | salary > 0 |
Internal Foreign Key Constraint | Affected Field | Source Schema | Source Table |
EMP_DEPT_FK | DEPARTMENT_ID | HR | DEPARTMENTS |
EMP_JOB_FK | JOB_ID | HR | JOBS |
EMP_MANAGER_FK | MANAGER_ID | HR | EMPLOYEES |
Primary Key as Foreign Key Constraint | Affected Schema | Affected Table | Affected Field |
CUSTOMERS_ACCOUNT_MANAGER_FK | OE | CUSTOMERS | ACCOUNT_MGR_ID |
DEPT_MGR_FK | HR | DEPARTMENTS | MANAGER_ID |
JHIST_EMP_FK | HR | JOB_HISTORY | EMPLOYEE_ID |
ORDERS_SALES_REP_FK | OE | ORDERS | SALES_REP_ID |
Trigger Name | Trigger |
UPDATE_JOB_HISTORY | TRIGGER update_job_history AFTER UPDATE OF job_id, department_id ON employees FOR EACH ROW BEGIN add_job_history(:old.employee_id, :old.hire_date, sysdate, :old.job_id, :old.department_id); END; |
jobs table with job titles and salary ranges. Contains 19 rows.
References with employees and job_history table.
Primary Key(s): JOB_ID
Field | Type | Nulls? | Comments |
JOB_ID | VARCHAR2 (10) | No | Primary key of jobs table. |
JOB_TITLE | VARCHAR2 (35) | No | A not null column that shows job title, e.g. AD_VP, FI_ACCOUNTANT |
MIN_SALARY | NUMBER (6) | Yes | Minimum salary for a job title. |
MAX_SALARY | NUMBER (6) | Yes | Maximum salary for a job title |
Index Name | Type | Unique | Fields |
JOB_ID_PK | NORMAL | Yes | JOB_ID |
No Check Constraints
No Internal Foreign Keys
Primary Key as Foreign Key Constraint | Affected Schema | Affected Table | Affected Field |
EMP_JOB_FK | HR | EMPLOYEES | JOB_ID |
JHIST_JOB_FK | HR | JOB_HISTORY | JOB_ID |
No Enabled Triggers
Table that stores job history of the employees. If an employee
changes departments within the job or changes jobs within the department,
new rows get inserted into this table with old job information of the
employee. Contains a complex primary key: employee_id+start_date.
Contains 25 rows. References with jobs, employees, and departments tables.
Primary Key(s): EMPLOYEE_ID, START_DATE
Field | Type | Nulls? | Comments |
EMPLOYEE_ID | NUMBER (6) | No | A not null column in the complex primary key employee_id+start_date. Foreign key to employee_id column of the employee table |
START_DATE | DATE | No | A not null column in the complex primary key employee_id+start_date. Must be less than the end_date of the job_history table. (enforced by constraint jhist_date_interval) |
END_DATE | DATE | No | Last day of the employee in this job role. A not null column. Must be greater than the start_date of the job_history table. (enforced by constraint jhist_date_interval) |
JOB_ID | VARCHAR2 (10) | No | Job role in which the employee worked in the past; foreign key to job_id column in the jobs table. A not null column. |
DEPARTMENT_ID | NUMBER (4) | Yes | Department id in which the employee worked in the past; foreign key to deparment_id column in the departments table |
Index Name | Type | Unique | Fields |
JHIST_DEPARTMENT_IX | NORMAL | No | DEPARTMENT_ID |
JHIST_EMPLOYEE_IX | NORMAL | No | EMPLOYEE_ID |
JHIST_EMP_ID_ST_DATE_PK | NORMAL | Yes | EMPLOYEE_ID, START_DATE |
JHIST_JOB_IX | NORMAL | No | JOB_ID |
Check Constraint Name | Text |
JHIST_DATE_INTERVAL | end_date > start_date |
Internal Foreign Key Constraint | Affected Field | Source Schema | Source Table |
JHIST_DEPT_FK | DEPARTMENT_ID | HR | DEPARTMENTS |
JHIST_EMP_FK | EMPLOYEE_ID | HR | EMPLOYEES |
JHIST_JOB_FK | JOB_ID | HR | JOBS |
No External Foreign Keys
No Enabled Triggers
Locations table that contains specific address of a specific office,
warehouse, and/or production site of a company. Does not store addresses /
locations of customers. Contains 23 rows; references with the
departments and countries tables.
Primary Key(s): LOCATION_ID
Field | Type | Nulls? | Comments |
LOCATION_ID | NUMBER (4) | No | Primary key of locations table |
STREET_ADDRESS | VARCHAR2 (40) | Yes | Street address of an office, warehouse, or production site of a company. Contains building number and street name |
POSTAL_CODE | VARCHAR2 (12) | Yes | Postal code of the location of an office, warehouse, or production site of a company. |
CITY | VARCHAR2 (30) | No | A not null column that shows city where an office, warehouse, or production site of a company is located. |
STATE_PROVINCE | VARCHAR2 (25) | Yes | State or Province where an office, warehouse, or production site of a company is located. |
COUNTRY_ID | CHAR (2) | Yes | Country where an office, warehouse, or production site of a company is located. Foreign key to country_id column of the countries table. |
Index Name | Type | Unique | Fields |
LOC_CITY_IX | NORMAL | No | CITY |
LOC_COUNTRY_IX | NORMAL | No | COUNTRY_ID |
LOC_ID_PK | NORMAL | Yes | LOCATION_ID |
LOC_STATE_PROVINCE_IX | NORMAL | No | STATE_PROVINCE |
No Check Constraints
Internal Foreign Key Constraint | Affected Field | Source Schema | Source Table |
LOC_C_ID_FK | COUNTRY_ID | HR | COUNTRIES |
Primary Key as Foreign Key Constraint | Affected Schema | Affected Table | Affected Field |
DEPT_LOC_FK | HR | DEPARTMENTS | LOCATION_ID |
WAREHOUSES_LOCATION_FK | OE | WAREHOUSES | LOCATION_ID |
No Enabled Triggers
Primary Key(s): REGION_ID
Field | Type | Nulls? |
REGION_ID | NUMBER | No |
REGION_NAME | VARCHAR2 (25) | Yes |
Index Name | Type | Unique | Fields |
REG_ID_PK | NORMAL | Yes | REGION_ID |
No Check Constraints
No Internal Foreign Keys
Primary Key as Foreign Key Constraint | Affected Schema | Affected Table | Affected Field |
COUNTR_REG_FK | HR | COUNTRIES | REGION_ID |
No Enabled Triggers
Field | Type | Nulls? |
EMPLOYEE_ID | NUMBER (6) | No |
JOB_ID | VARCHAR2 (10) | No |
MANAGER_ID | NUMBER (6) | Yes |
DEPARTMENT_ID | NUMBER (4) | Yes |
LOCATION_ID | NUMBER (4) | Yes |
COUNTRY_ID | CHAR (2) | Yes |
FIRST_NAME | NVARCHAR2 (20) | Yes |
LAST_NAME | VARCHAR2 (25) | No |
SALARY | NUMBER (8, 2) | Yes |
COMMISSION_PCT | NUMBER (2, 2) | Yes |
DEPARTMENT_NAME | VARCHAR2 (30) | No |
JOB_TITLE | VARCHAR2 (35) | No |
CITY | VARCHAR2 (30) | No |
STATE_PROVINCE | VARCHAR2 (25) | Yes |
COUNTRY_NAME | VARCHAR2 (40) | Yes |
REGION_NAME | VARCHAR2 (25) | Yes |
SELECT
e.employee_id,
e.job_id,
e.manager_id,
e.department_id,
d.location_id,
l.country_id,
e.first_name,
e.last_name,
e.salary,
e.commission_pct,
d.department_name,
j.job_title,
l.city,
l.state_province,
c.country_name,
r.region_name
FROM
employees e,
departments d,
jobs j,
locations l,
countries c,
regions r
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id
AND l.country_id = c.country_id
AND c.region_id = r.region_id
AND j.job_id = e.job_id
WITH READ ONLY
All Stored Procedures (Stored Procedures)
Parameter | Type | In/Out |
P_EMP_ID | NUMBER (6) | IN |
P_START_DATE | DATE | IN |
P_END_DATE | DATE | IN |
P_JOB_ID | VARCHAR2 (MAX) | IN |
P_DEPARTMENT_ID | NUMBER (4) | IN |
PROCEDURE add_job_history
( p_emp_id job_history.employee_id%type
, p_start_date job_history.start_date%type
, p_end_date job_history.end_date%type
, p_job_id job_history.job_id%type
, p_department_id job_history.department_id%type
)
IS
BEGIN
INSERT INTO job_history (employee_id, start_date, end_date,
job_id, department_id)
VALUES(p_emp_id, p_start_date, p_end_date, p_job_id, p_department_id);
END add_job_history;
No Parameters
PROCEDURE secure_dml
IS
BEGIN
IF TO_CHAR (SYSDATE, 'HH24:MI') NOT BETWEEN '08:00' AND '18:00'
OR TO_CHAR (SYSDATE, 'DY') IN ('SAT', 'SUN') THEN
RAISE_APPLICATION_ERROR (-20205,
'You may only make changes during normal office hours');
END IF;
END secure_dml;