CREATE VIEW

Create a view

Synopsis:

 CREATE [TEMP | TEMPORARY] VIEW [IF NOT EXISTS] [database-name.] 
  view-name AS select-statement 

Description:

The CREATE VIEW command assigns a name to a prepackaged SELECT statement. Once the view is created, it can be used in the FROM clause of another SELECT in place of a table name.

The TEMP or TEMPORARY keyword means that the newly created view is visible only to the process that opened the database, and that the view is automatically deleted when the database is closed.

If database-name is specified, then the view is created in the named database. It is an error to specify both database-name and the TEMP keyword, unless database-name is temp. If no database name is specified and the TEMP keyword is not present, the table is created in the main database.

Views are read-only in QDB, so you cannot run COPY, DELETE, INSERT, or UPDATE on a view. However, in many cases you can use a CREATE TRIGGER on the view to accomplish the same thing. Views are removed with the DROP VIEW command.