sql / intermediate
Snippet
Restricting Sensitive Column Access via Security Views
Views serve as a fundamental security mechanism in SQL databases. Creating dedicated views allows database administrators to expose non-sensitive fields and pre-filtered active records to application users while hiding restricted columns like salaries or social security numbers.
snippet.sql
sql
1
2
3
4
5
6
7
8
CREATE VIEW public_employee_directory ASSELECTemployee_id,first_name,last_name,department_idFROM employeesWHERE is_active = 1;
Breakdown
1
CREATE VIEW public_employee_directory AS
Defines a virtual table to encapsulate security and access rules.
2
employee_id,
Includes non-sensitive operational columns in the public projection.
3
FROM employees
References the base underlying relation containing complete workforce data.
4
WHERE is_active = 1;
Filters out inactive employee records automatically for all consumers of this view.