-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_objects.sql
104 lines (70 loc) · 3.24 KB
/
Create_objects.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- ***********************************************************************
-- *
-- * Program : CreateObjects.sql
-- * Purpose : Script to create database objects:
-- * Tables: Employees, Departments, contraints and sequences
-- * Remarks : Run the script in the SQLPLUS prompt by running the following command:
-- * @create_oobjects.sql
-- ***********************************************************************
-- Please uncomment the following to drop the tables if already created
/*
DROP table departments;
DROP table Employees;
*/
Prompt 'Creating departments table
CREATE TABLE departments (
department_id NUMBER(10) NOT NULL,
department_name VARCHAR2(50) NOT NULL,
location VARCHAR2(50) NOT NULL
);
COMMENT ON COLUMN departments.department_id IS
'The unique identifier for the department';
COMMENT ON COLUMN departments.department_name IS
'The name of the department';
COMMENT ON COLUMN departments.location IS
'The physical location of
the department';
ALTER TABLE departments ADD CONSTRAINT department_pk PRIMARY KEY ( department_id );
Prompt 'Departments table and primary key constrains created
Prompt 'Creating Employees table
CREATE TABLE employees (
employee_id NUMBER(10) NOT NULL,
employee_name VARCHAR2(50) NOT NULL,
job_title VARCHAR2(50) NOT NULL,
date_hired DATE NOT NULL,
salary NUMBER(10) NOT NULL,
department_id NUMBER(5) NOT NULL,
manager_id NUMBER(10)
);
COMMENT ON COLUMN employees.employee_id IS
'The unique identifier for the employee';
COMMENT ON COLUMN employees.employee_name IS
'The name of the employee';
COMMENT ON COLUMN employees.job_title IS
'The job role undertaken by the employee. Some employees may undertaken the same job role';
COMMENT ON COLUMN employees.date_hired IS
'The date the employee was hired
';
COMMENT ON COLUMN employees.salary IS
'Current salary of the employee';
ALTER TABLE employees ADD CONSTRAINT employee_pk PRIMARY KEY ( employee_id );
ALTER TABLE employees
ADD CONSTRAINT employee_department_fk FOREIGN KEY ( department_id )
REFERENCES departments ( department_id );
ALTER TABLE employees
ADD CONSTRAINT employee_employee_fk FOREIGN KEY ( manager_id )
REFERENCES employees ( employee_id );
Prompt 'Employees table and primary key constrains created
Prompt 'Creating sequences for Employee_id and Department_id
-- DROP sequence DEPTSEQ;
CREATE SEQUENCE "DEPTSEQ" MINVALUE 1 MAXVALUE 999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL ;
-- DROP sequence empseq;
CREATE SEQUENCE "EMPSEQ" MINVALUE 90001 MAXVALUE 9999999 INCREMENT BY 1 START WITH 90001 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE GLOBAL ;
Prompt 'Sequences Created
-- Create the package specification
Prompt 'Creating package specification pkg_employee_api
@pkg_employee_api.pls
Prompt 'package specification pkg_employee_api created
Prompt 'Creating package body pkg_employee_api
@pkg_employee_api.plb
Prompt 'package body pkg_employee_api created