Previous Topic

Next Topic

Creating Views

The CREATE VIEW statement allows creation of a view with the specified name on existing tables or views. The following example shows the usage of CREATE VIEW statement in ESQL programs:

Example Creating Views


...
/* connect to a default database */
EXEC SQL CONNECT TO DEFAULT ;

/* create a view ne_customer in the database */
EXEC SQL
   CREATE VIEW ne_customer AS
      SELECT CUST_NO, name, street, city, state
      FROM customer
      WHERE state IN ('NH', 'MA', 'NY', 'ME', 'VT') ;
if (sqlca.sqlcode)
{
  fprintf (stderr,
  "Create view statement failed (%ld : %s) \n",
  sqlca.sqlcode, sqlca.sqlerrm);

EXEC SQL ROLLBACK WORK ;
  EXEC SQL DISCONNECT DEFAULT ;
  exit (1);
}
/* Commit changes */
EXEC SQL COMMIT WORK ;

printf ("View ne_customer created. \n");

/* Disconnect from the database */
EXEC SQL DISCONNECT DEFAULT ;
...

The previous example shows creation of a view ne_customer on the table customer.