sql / expert
Snippet
Data Integrity via WITH CHECK OPTION
The WITH CHECK OPTION clause on a view prevents users from inserting or updating rows that would not be visible through the view itself. This enforces business logic at the schema level, ensuring data consistency for updatable views.
snippet.sql
1
2
3
4
5
CREATE VIEW Active_Staff ASSELECT id, name, statusFROM EmployeesWHERE status = 'ACTIVE'WITH CHECK OPTION;
Breakdown
1
WHERE status = 'ACTIVE'
Defines the filter criteria for the view's contents.
2
WITH CHECK OPTION
Mandates that any DML operation via this view must satisfy the WHERE clause.