Hitachi

Hitachi Advanced Database Setup and Operation Guide


11.2.1 Defining a viewed table

To define a viewed table, execute the CREATE VIEW definition SQL statement.

The following shows an example of defining a viewed table.

Example

From the CUSTOMER and STOCK base tables, a viewed table named CUSTOMER30s is defined that lists the products purchased by customers in their 30's.

Figure 11‒1: Example of CUSTOMER and STOCK base tables

[Figure]

■ SQL statement for defining the viewed table (CUSTOMER30s table)
CREATE VIEW "CUSTOMER30s"
  ("AGE","SEX","GNO","PNAME","PRICE")
  AS SELECT
   "CUSTOMER"."AGE", "CUSTOMER"."SEX", "CUSTOMER"."GNO",
   "STOCK"."PNAME", "STOCK"."PRICE"
  FROM "CUSTOMER","STOCK"
    WHERE "CUSTOMER"."AGE"=30 AND "CUSTOMER"."GNO"="STOCK"."GNO"
Figure 11‒2: Example of definition of the viewed table (CUSTOMER30s table)

[Figure]

Whether the defined viewed table becomes an updatable viewed table or a read-only viewed table depends on what is specified in AS query specification in the CREATE VIEW statement. For details, see CREATE VIEW (define a viewed table) in Definition SQL in the manual HADB SQL Reference.