HPlogo Up and Running with ALLBASE/SQL: HP 3000 and HP 9000 Computer Systems > Chapter 3 Setting Up a Database with ISQL

Creating Views

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

When you need to perform a query frequently, you can define a view that incorporates the column list and the predicate; then you can select from the view with a simpler statement.

As an example, create a view of the Albums and Titles tables that includes all selections:

   isql=> CREATE VIEW Selections AS Return

   > SELECT AlbumTitle, Selection, Return

   > Composer FROM Albums, Titles Return

   > WHERE Albums.AlbumCode =  Return

   > Titles.AlbumCode; Return

Now use the following simple SELECT statement to display all selections by Palestrina:

   SELECT * FROM Selections Return

   > WHERE Composer = 'Palestrina'; Return

Views are useful when you want to define specific subsets of data that are frequently used or when you want to restrict access to particular subsets. You can create views and grant access to them, then revoke access to the underlying base tables.

Did you remember to COMMIT WORK? This makes the view definition permanent in the DBEnvironment.

For more information about views, see the CREATE VIEW statement in the "SQL Queries" chapter of the ALLBASE/SQL Reference Manual.

Feedback to webmaster