sql / intermediate
Snippet
Restricting Sensitive Data Exposure via Dynamic Views
Views serve as virtual tables that hide underlying schema complexity and restrict column or row exposure. By exposing a curated view instead of direct table access, sensitive data like salary or home address remains secure.
snippet.sql
sql
1
2
3
4
5
6
7
8
9
CREATE VIEW public_employee_directory ASSELECTemployee_id,first_name,last_name,department_id,COALESCE(work_email, 'N/A') AS contact_emailFROM employeesWHERE status = 'ACTIVE';
Breakdown
1
CREATE VIEW public_employee_directory AS
Establishes a named virtual dataset based on a predefined SQL query.
2
employee_id, first_name, last_name, department_id,
Explicitly selects non-sensitive columns while excluding confidential fields.
3
COALESCE(work_email, 'N/A') AS contact_email
Provides a fallback text string when the email address column contains NULL.
4
WHERE status = 'ACTIVE';
Enforces row-level filtering to present only currently employed personnel.