How to create a View in DB2 an example SQL

How to create Views in database
[How to create Views in database]
Views in database or any RDBMS are not physical tables. You create views only on base tables. If there are no base tables present, then there is no concept of Views.

  • Views are not physical tables.
  • Tables are physical tables.
  • When physical table is deleted from database the corresponding views will give an error
  • You cannot delete records from view since no records present in views -those are present in base tables only

You are creating views because of the following reasons:

  • Control access to a table
  • Make data easier to use
  • Simplify authorization by granting access to a view without granting access to the table
  • Show only portions of data in the table
  • Show summary data for a given table
  • Combine two or more tables in meaningful ways
  • Show only the selected rows that are pertinent to the process that uses the view

Also read: Instant SQL formatter for Your Projects

The below are the two best examples and syntax to create views

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'

Author: Srini

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