How to create a View in DB2 an example SQL

How to create Views in database
[How to create Views in database]
Views in DB2 database are not physical tables. We create a view on base tables. If there are no base tables present then there is no concept of View. 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

More: Instant SQL formatter for Your Projects, a handy tool

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

Example – 1

CREATE VIEW ma_proj AS
SELECT *
FROM   project
WHERE  substr(projno, 1, 2) = ‘MA’

Example -2

CREATE VIEW ma_proj AS selectprojno,
projname,
respemp
FROM        project
WHERE       substr
(
projno,
1,
2
)
= ‘MA’

Advertisements

Author: Srini

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