forked from OpenLinkSoftware/SQL-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oracle-hr-for-virtuoso.sql
116 lines (80 loc) · 3.2 KB
/
oracle-hr-for-virtuoso.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
105
106
107
108
109
110
111
112
113
114
115
116
-- Adapted from version at: http://www.sqltutorial.org/sql-sample-database/
-- Clean up
DROP TABLE hr.demo.dependents ;
DROP TABLE hr.demo.employees ;
DROP TABLE hr.demo.jobs ;
DROP TABLE hr.demo.departments ;
DROP TABLE hr.demo.locations ;
DROP TABLE hr.demo.countries ;
DROP TABLE hr.demo.regions ;
-- Create new Tables/Relations
CREATE TABLE hr.demo.regions (
region_id INT IDENTITY PRIMARY KEY,
region_name VARCHAR (25) DEFAULT NULL
);
CREATE TABLE hr.demo.countries (
country_id CHAR (2) PRIMARY KEY,
country_name VARCHAR (40) DEFAULT NULL,
region_id INT NOT NULL,
FOREIGN KEY (region_id) REFERENCES hr.demo.regions (region_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE hr.demo.locations (
location_id INT IDENTITY PRIMARY KEY,
street_address VARCHAR (40) DEFAULT NULL,
postal_code VARCHAR (12) DEFAULT NULL,
city VARCHAR (30) NOT NULL,
state_province VARCHAR (25) DEFAULT NULL,
country_id CHAR (2) NOT NULL,
FOREIGN KEY (country_id) REFERENCES hr.demo.countries (country_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE hr.demo.jobs (
job_id INT IDENTITY PRIMARY KEY,
job_title VARCHAR (35) NOT NULL,
min_salary DECIMAL (8, 2) DEFAULT NULL,
max_salary DECIMAL (8, 2) DEFAULT NULL
);
CREATE TABLE hr.demo.departments (
department_id INT IDENTITY PRIMARY KEY,
department_name VARCHAR (30) NOT NULL,
location_id INT DEFAULT NULL,
FOREIGN KEY (location_id) REFERENCES hr.demo.locations (location_id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE hr.demo.employees (
employee_id INT IDENTITY PRIMARY KEY,
first_name VARCHAR (20) DEFAULT NULL,
last_name VARCHAR (25) NOT NULL,
email VARCHAR (100) NOT NULL,
phone_number VARCHAR (20) DEFAULT NULL,
hire_date DATE NOT NULL,
job_id INT NOT NULL,
salary DECIMAL (8, 2) NOT NULL,
manager_id INT DEFAULT NULL,
department_id INT DEFAULT NULL,
FOREIGN KEY (job_id) REFERENCES hr.demo.jobs (job_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (department_id) REFERENCES hr.demo.departments (department_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (manager_id) REFERENCES hr.demo.employees (employee_id)
);
CREATE TABLE hr.demo.dependents (
dependent_id INT IDENTITY PRIMARY KEY,
first_name VARCHAR (50) NOT NULL,
last_name VARCHAR (50) NOT NULL,
relationship VARCHAR (25) NOT NULL,
employee_id INT NOT NULL,
FOREIGN KEY (employee_id) REFERENCES hr.demo.employees (employee_id) ON DELETE CASCADE ON UPDATE CASCADE
);
-- Grants to SPARQL Role
GRANT SELECT ON hr.demo.departments TO vdb;
GRANT SELECT ON hr.demo.locations TO vdb;
GRANT SELECT ON hr.demo.countries TO vdb;
GRANT SELECT ON hr.demo.regions TO vdb;
GRANT SELECT ON hr.demo.jobs TO vdb;
GRANT SELECT ON hr.demo.employees TO vdb;
GRANT SELECT ON hr.demo.dependents TO vdb;
-- Grants to SPARQL_SELECT Role
GRANT SELECT ON hr.demo.departments TO vdb ;
GRANT SELECT ON hr.demo.locations TO vdb ;
GRANT SELECT ON hr.demo.countries TO vdb ;
GRANT SELECT ON hr.demo.regions TO vdb ;
GRANT SELECT ON hr.demo.jobs TO vdb ;
GRANT SELECT ON hr.demo.employees TO vdb ;
GRANT SELECT ON hr.demo.dependents TO vdb ;