HP Neoview SQL Reference Manual page 106

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

CREATE VIEW SALES.MYVIEW1 AS
SELECT ordernum, qty_ordered FROM SALES.ODETAIL;
This example creates a view with a column list:
CREATE VIEW SALES.MYVIEW2
(v_ordernum, t_partnum) AS
SELECT v.ordernum, t.partnum
FROM SALES.MYVIEW1 v, SALES.ODETAIL t;
This example creates a view from two tables by using an INNER JOIN:
CREATE VIEW MYVIEW4
(v_ordernum, v_partnum) AS
SELECT od.ordernum, p.partnum
FROM SALES.ODETAIL OD INNER JOIN SALES.PARTS P
ON od.partnum = p.partnum;
Vertical Partition Example
This example creates three logical vertical partitions for a table, vp0, vp1, and vp2 and then
creates a view vp to access them.
A view can be used to obtain a composite representation of a set of closely related tables. In the
following example tables vp0, vp1 and vp2 all have a key column a. This key column is known
to contain identical rows for all three tables. The three tables vp0, vp1 and vp2 also contain
columns b, c and d respectively. We can create a view vp that combines these three tables and
provides the interface of columns a, b, c and d belonging to a single object.
Neoview SQL has the ability to eliminate redundant joins in a query. Redundant joins occur
when
Output of join contains expressions from only one of its two children
Every row from this child will match one and only one row from the other child
Suppose tables A and B denote generic tables. To check if the rule "every row from this child
will match one and only one row from the other child" is true, Neoview SQL uses the fact that
the join of Table A with table or subquery B preserves all the rows of A if the join predicate
contains an equi-join predicate that references a key of B, and one of the following is true: The
equi-join predicate references only the key and there is a NOT ENFORCED referential constraint
between A(foreign key) and B(key) and there are no local predicates on B, or the join is a left
outer join where B is the inner table. In this example, for the join between vp0 and vp1, vp0 fills
the role of table A and vp1 fills the role of table B. For the join between vp1 and vp2, vp1 fills
the role of table A and vp2 fills the role of table B.
The view vp shown in this example uses left outer joins to combine the three underlying tables.
Therefore, if the select list in a query that accesses vp does not contain column d from vp2 then
the join to table vp2 in the view vp will not be performed. The NOT ENFORCED referential
constraint appears as an option in the HP Database Manager. It can also be used in the Neoview
Command Interface (NCI) product.
NOTE:
The NOT ENFORCED referential constraint (REFERENCES/FOREIGN KEY) is used
to help the optimizer eliminate redundant joins, and not to enforce referential integrity.
create table vp0(a integer not null, b integer, primary key(a));
create table vp1(a integer not null, c integer, primary key(a));
create table vp2(a integer not null, d integer, primary key(a));
create view vp(a,b,c,d) as
select vp0.a, b, c, d
from vp0 left outer join vp1 on vp0.a=vp1.a
left outer join vp2 on vp0.a=vp2.a;
select a, b from vp;
106
SQL Statements
-- reads only vp0

Advertisement

Table of Contents
loading

Table of Contents