In this lesson we will learn how to modify the data in a view.

We'll cover the following

Updatable Views

Views are not only used to query data; they can also be used to update data in the underlying tables. It is possible to insert or update rows in the base table, and in the same vein, delete rows from the table using an updatable view. In order for a view to become updatable, it must abide by certain conditions.

If the SELECT query that creates the view has aggregate functions (MAX, MIN, COUNT, SUM, etc.), DISTINCT keyword, LEFT JOIN or GROUP BY, HAVING, and UNION clauses, the resulting view will not be updatable. Similarly, a subquery that refers to the same table that appears in the FROM clause prohibits updates to the base table.

Syntax

UPDATE view

SET col1 = value1, col2 = value2,…coln = valuen

WHERE <condition>

Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/42lesson.sh and wait for the MySQL prompt to start-up.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.