Create a View
CREATE VIEW departments_hq AS
SELECT department_id, department_name, location_id
FROM hr.departments
WHERE location_id = 1700
WITH CHECK OPTION CONSTRAINT departments_hq_cnst
View created.
Query the View
SELECT * FROM departments_hq
DEPARTMENT_ID | DEPARTMENT_NAME | LOCATION_ID | 10 | Administration | 1700 | 30 | Purchasing | 1700 | 90 | Executive | 1700 | 100 | Finance | 1700 | 110 | Accounting | 1700 | 120 | Treasury | 1700 | 130 | Corporate Tax | 1700 | 140 | Control And Credit | 1700 | 150 | Shareholder Services | 1700 | 160 | Benefits | 1700 | 170 | Manufacturing | 1700 | 180 | Construction | 1700 | 190 | Contracting | 1700 | 200 | Operations | 1700 | 210 | IT Support | 1700 | 220 | NOC | 1700 | 230 | IT Helpdesk | 1700 | 240 | Government Sales | 1700 | 250 | Retail Sales | 1700 | 260 | Recruiting | 1700 | 270 | Payroll | 1700 |
---|
Replace the View with an Modified Query
CREATE OR REPLACE VIEW departments_hq AS
SELECT department_id, department_name, manager_id
FROM hr.departments
WHERE location_id = 1700
WITH CHECK OPTION CONSTRAINT departments_hq_cnst
View created.
Query the View
SELECT * FROM departments_hq
DEPARTMENT_ID | DEPARTMENT_NAME | MANAGER_ID | 10 | Administration | 200 | 30 | Purchasing | 114 | 90 | Executive | 100 | 100 | Finance | 108 | 110 | Accounting | 205 | 120 | Treasury | - | 130 | Corporate Tax | - | 140 | Control And Credit | - | 150 | Shareholder Services | - | 160 | Benefits | - | 170 | Manufacturing | - | 180 | Construction | - | 190 | Contracting | - | 200 | Operations | - | 210 | IT Support | - | 220 | NOC | - | 230 | IT Helpdesk | - | 240 | Government Sales | - | 250 | Retail Sales | - | 260 | Recruiting | - | 270 | Payroll | - |
---|
Drop the View
DROP VIEW departments_hq
View dropped.