TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

DB2 - SQL Create View Statement


A view provides a different way of looking at the data in one or more tables. View is a virtual table consisting of a SQL SELECT statement that accesses data from one or more tables or views.

A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.

Following is the view creation syntax.

CREATE VIEW view-name
    AS query

Where, Query means any SQL SELECT statement.

Example:

Create a view named VW_PROJECT upon the TB_PROJECT table that contains only those rows with a project number (PROJECT_NO) starting with the letters 'SP'.

CREATE VIEW VW_PROJECT
    AS SELECT *
      FROM TB_PROJECT
        WHERE SUBSTR(PROJECT_NO, 1, 2) = 'SP'

We can query the view above as follows:

SELECT * FROM [VW_PROJECT];


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal