next up previous
Next: Modification of the Database Up: Derived Relations Previous: Derived Relations

Views

  1. A view in SQL is defined using the create view command:

     create view v as  tex2html_wrap_inline1822 query expression tex2html_wrap_inline1824  
    

    where tex2html_wrap_inline1822 query expression tex2html_wrap_inline1824 is any legal query expression.

    The view created is given the name v.

  2. To create a view all-customer of all branches and their customers:

     create view all-customer as
    

    (select bname, cname

    from depositor, account

    where depositor.account# = account.account#)

    union

    (select bname, cname

    from borrower, loan

    where borrower.loan# = loan.loan#)

  3. Having defined a view, we can now use it to refer to the virtual relation it creates. View names can appear anywhere a relation name can.
  4. We can now find all customers of the SFU branch by writing

     select cname
    

    from all-customer

    where bname=``SFU''



Osmar Zaiane
Fri May 22 19:39:12 PDT 1998