Hrschema
Hrschema
01 Create Account
Create accounts for HR schema
Run this as either SYS or SYSTEM.
*/
/*
Set the pluggable database if you're running this on Oracle v12 or later.
*/
ALTER SESSION SET CONTAINER = ORCLPDB1;
/*
Drop the HR account and all objects to reset.
Then, create the user and give it the permissions.
*/
DROP USER HR CASCADE;
GRANT CREATE SESSION, CREATE VIEW, CREATE TABLE, ALTER SESSION, CREATE SEQUENCE TO
HR;
GRANT CREATE SYNONYM, CREATE DATABASE LINK, RESOURCE, UNLIMITED TABLESPACE TO HR;
/*
02 Create Tables
This script creates the tables needed for the HR schema.
Run this script after script 01, and while you are logged in as the newly-created
HR user.
*/
/* Regions */
/* Countries */
/* Locations */
/* Departments */
/* Jobs */
/* Employees */
/* Alter Tables */
/* Job History */
CREATE TABLE job_history (
employee_id NUMBER(6) CONSTRAINT jhist_employee_nn NOT NULL,
start_date DATE CONSTRAINT jhist_start_date_nn NOT NULL,
end_date DATE CONSTRAINT jhist_end_date_nn NOT NULL,
job_id VARCHAR2(10) CONSTRAINT jhist_job_nn NOT NULL,
department_id NUMBER(4),
CONSTRAINT jhist_date_interval CHECK (end_date > start_date)
);
COMMIT;
/*
03 Populate Tables
This script populates the tables that were created in the previous script.
*/
COMMIT;
/*
04 Others
Perform other steps after populating data, such as indexes and comments
*/
COMMIT;
/*
procedure and statement trigger to allow dmls during business hours:
*/
/*
procedure to add a row to the JOB_HISTORY table and row trigger
to call the procedure when data is updated in the job_id or
department_id columns in the EMPLOYEES table:
*/
COMMIT;
/*
Add comments to tables and columns
*/
COMMIT;