next up previous
Next: Indexes Up: ADDITIONAL FEATURES OF SQL Previous: ADDITIONAL FEATURES OF SQL

Views

CREATE VIEW view-name [(col-list)]
  AS select-statement

DROP VIEW view-name

SQL> CREATE VIEW dallas_cust AS 
       select *
       from customers
       where city = 'Dallas';

View created.

SQL> select * 
     from dallas_cust;

CID  CNAME         CITY                     DISCNT
---- ------------- -------------------- ----------
c002 Basics        Dallas                       12
c003 Allied        Dallas                        8

SQL> CREATE VIEW tot_sales_per_agent AS
       select agents.aid, aname, sum(dollars) TOT_SALES
       from agents,orders
       where agents.aid = orders.aid
       group by agents.aid,aname;

View Created
SQL> select * 
     from tot_sales_per_agent;

AID ANAME          TOT_SALES
--- ------------- ----------
a01 Smith               1400
a02 Jones                180
a03 Brown               4228
a04 Gray                 450
a05 Otasi               2144
a06 Smith               1400



Raj Sunderraman
Tue Apr 1 16:15:10 PST 1997