How to Create a View in DB2 SQL

Views are logical tables on top of a physical table you can create. If there are no base tables, there is no concept of Views.

Rules to create a View

  • It gives an error if the physical table is not present in the database.
  • You cannot delete records in the view since it’s logical.

Types of Views

3 Types of SQL Views

Purpose of Views

  • Control access to table-data
  • Make data easier-to-use
  • Simplify authorization; you can give access to only a view instead of the table
  • Show only portions of table-data
  • Show summary of a table
  • Combine two or more tables in meaningful ways
  • Show only the selected rows that are pertinent to the process that uses the view

Read: Instant SQL format Tool for Your Projects

Examples to Create a View

Example – 1

FROM   project
WHERE  substr(projno, 1, 2) = 'MA'

Example -2

CREATE VIEW ma_proj AS selectprojno,
projname, respemp
FROM        project
WHERE       substr
= 'MA'

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.