Start Updating a view in sql

Updating a view in sql

You can think of a view as a lens looking at one or more tables.

You can clearly see that I did not do such a good job with this. This SELECT can include a WHERE clause or anything else for that matter that can be put into a SELECT statement. This is a pretty common thing to do, By having a view that already does this we save having to write that function in every query where this is a requirement.

A view can contain all rows of a table or select rows from a table.

A view can be created from one or many tables which depends on the written SQL query to create a view.

A view can be updated under certain conditions which are given below − ---- ---------- ----- ----------- ---------- | ID | NAME | AGE | ADDRESS | SALARY | ---- ---------- ----- ----------- ---------- | 1 | Ramesh | 35 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | kaushik | 23 | Kota | 2000.00 | | 4 | Chaitali | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 | | 7 | Muffy | 24 | Indore | 10000.00 | ---- ---------- ----- ----------- ---------- Rows of data can be inserted into a view.

The same rules that apply to the UPDATE command also apply to the INSERT command.

Here, we cannot insert rows in the CUSTOMERS_VIEW because we have not included all the NOT NULL columns in this view, otherwise you can insert rows in a view in a similar way as you insert them in a table. The same rules that apply to the UPDATE and INSERT commands apply to the DELETE command.

Following is an example to delete a record having AGE = 22.

Introduction As I wrote in the previous article, you can update records via a view in SQL but there are some restrictions, for example you can't update records in multiple tables when the view references more than one base table.