Privileges when using a view
When you attempt to use a view, the database server tests only the privileges that you are granted on the view. It does not test your right to access the underlying tables.
If you create the view, your privileges are the ones noted in the preceding section. If you are not the creator, you have the privileges that the creator (or someone who had the WITH GRANT OPTION privilege) granted you.
CREATE TABLE hr_data
(
emp_key INTEGER,
emp_name CHAR(40),
hire_date DATE,
dept_num SMALLINT,
user-id CHAR(18),
salary DECIMAL(8,2),
performance_level CHAR(1),
performance_notes TEXT
)
REVOKE ALL ON hr_data FROM PUBLIC
CREATE VIEW hr_public AS
SELECT emp_key, emp_name, hire_date, dept_num, user_id
FROM hr_data
CREATE VIEW hr_enter AS
SELECT emp_key, emp_name, hire_date, dept_num
FROM hr_data
You grant these users both Select and Insert privileges on this view. Because you, the creator of both the table and the view, have the Insert privilege on the table and the view, you can grant the Insert privilege on the view to others who have no privileges on the table.
CREATE VIEW hr_MIS AS
SELECT emp_key, emp_name, user_id
FROM hr_data
This view differs from the previous view in that it does not expose the department number and date of hire.
CREATE VIEW hr_mgr_data AS
SELECT * FROM hr_data
WHERE dept_num =
(SELECT dept_num FROM hr_data
WHERE user_id = USER)
AND NOT user_id = USER
GRANT SELECT, UPDATE (performance_level, performance_notes)
ON hr_mgr_data TO peter_m