Chapter - 4: Let's Make Coding Fun!
Chapter - 4: Let's Make Coding Fun!
VIEWS
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.
Example
NAME AGE
Ronie 35
Kelvin 25
John 23
The WITH CHECK OPTION in this case should deny the entry of any
NULL values in the view's AGE column, because the view is defined
by data that does not have a NULL value in the AGE column.
Updating a View
So, if a view satisfies all the above-mentioned rules then you can
update that view. The following code block has an example to
update the age of Ramesh.
This would ultimately update the base table CUSTOMERS and the
same would reflect in the view itself. Now, try to query the base
table and the SELECT statement would produce the following
result.
ID NAME AGE ADDRESS SALARY
ER1 Ronie 35 Amsterdam 2000.00
ER2 Kelvin 25 Durban 1200.00
ER3 John 23 Sydney 2300.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.
Rows of data can be deleted from a view. The same rules that apply
to the UPDATE and INSERT commands apply to the DELETE
command.
Obviously, where you have a view, you need a way to drop the view
if it is no longer needed. The syntax is very simple and is given
below − DROP VIEW view_name; Following is an example to drop
the CUSTOMERS_VIEW from the CUSTOMERS table.
PRACTICE
CONCLUSION
In this chapter, we showed how to create views and learned the
importance of views in the database.