Views
Views
We define a view in SQL by using the create view command. To define a view, we must give the view a name and must state the query that computes the view. The form of the create view command is
create view v as <query expression>
where <query expression> is any legal query expression. The view name is represented by v. Observe that the notation that we used for view definition in the relational algebra (see Chapter 3) is based on that of SQL.
As an example, consider the view consisting of branch names and the names of customers who have either an account or a loan at that branch. Assume that we want this view to be called all-customer. We define this view as follows:
The preceding view gives for each branch the sum of the amounts of all the loans at the branch. Since the expression sum(amount) does not have a name, the attribute name is specified explicitly in the view definition.
View names may appear in any place that a relation name may appear. Using the view all-customer, we can find all customers of the Perryridge branch by writing
Comments
Post a Comment