1968
MariaDBERRORNotableViewHIGH confidence

CHECK OPTION on a non-updatable view

Production Risk

None — view creation is rejected.

What this means

WITH CHECK OPTION was specified on a view that is not updatable. CHECK OPTION can only be applied to updatable views.

Why it happens
  1. 1CREATE VIEW ... WITH CHECK OPTION on a view using GROUP BY, DISTINCT, aggregate functions, UNION, or subqueries that make it non-updatable.
How to reproduce
trigger — this will error
trigger — this will error
CREATE VIEW v AS SELECT dept, COUNT(*) cnt FROM emp GROUP BY dept WITH CHECK OPTION;

expected output

ERROR 1968 (HY000): CHECK OPTION on non-updatable view 'db'.'v'.

Fix 1

Remove WITH CHECK OPTION from non-updatable views

Remove WITH CHECK OPTION from non-updatable views
CREATE VIEW v AS SELECT dept, COUNT(*) cnt FROM emp GROUP BY dept;

Why this works

WITH CHECK OPTION is only meaningful (and allowed) on updatable views.

Fix 2

Use an updatable view if CHECK OPTION is needed

Use an updatable view if CHECK OPTION is needed
CREATE VIEW v AS SELECT id, dept, salary FROM emp WHERE dept = 'HR' WITH CHECK OPTION;

Why this works

A simple view without aggregates is updatable and can use WITH CHECK OPTION.

Sources
Official documentation ↗

MySQL 8.0 — 1968 ER_VIEW_NONUPD_CHECK

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors