Java Reference
In-Depth Information
in depth later in this chapter. There are also extensive
examples in subsequent chapters, particularly in Chapter 7 .
Cross-Reference
Altering a view
Since a view is created using a SELECT command, views are altered using the
ALTER command to issue a new SELECT command. For example, to alter the view
you have just created, use the following command:
ALTER VIEW ViewCorleones AS
SELECT FIRST_NAME,LAST_NAME
FROM CUSTOMERS
WHERE Last_Name = 'Corleone'
You can use a view for updating or deleting rows, as well as for retrieving data. Since
the view is not a table in its own right, but merely a way of looking at a table, rows
updated or deleted in the view are updated or deleted in the original table.
For example, you can use the view created earlier in this chapter to change Vito
Corleone's street address, using this SQL statement:
UPDATE ViewCorleones
SET Street = '19 Main'
WHERE First_Name = 'Vito'
This example illustrates one of the advantages of using a view. A lot of the filtering
required to identify the target row is done in the view, so the SQL code is simpler and
more maintainable. In a nontrivial example, this can be a worthwhile improvement.
Views are, in a sense, queries that you can save by name, because
database management systems generally save views by associating the
SELECT statement used to create the view with the name of the view and
execute the SELECT when you want to access the view. The downside is
that this obviously adds some overhead each time you use a view.
Note
Data Manipulation Language
The Data Manipulation Language (DML) is used to insert data into a table and, when
necessary, to modify or delete data. SQL provides the three following statements you
can use to manipulate data within a database:
 
INSERT
 
UPDATE
 
DELETE
These statements are discussed in the following sections.
Search WWH ::




Custom Search