Skip to main content

Can you delete data through a view?

Yes, you can delete data through a view, but - just like with insert and update - only if the view is simple.

That is, it has to be built on a single table, with no JOIN, GROUP BY, DISTINCT, subqueries, or aggregate functions.

Example: it works

sql
CREATE VIEW active_users AS SELECT id, name FROM users WHERE is_active = 1; DELETE FROM active_users WHERE id = 5;

This command deletes the record from the users table, because active_users references it directly.

But if a view is complex (e.g. it combines several tables), then you can't delete through it - the database doesn't know which specific table to remove the data from.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.