DB2 SQL: How to create a View Best Example

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.

How to create Views in database
[How to create Views in database]

Top Rules 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

3 Types of Views

3 Types of SQL Views

Reasons to Create a View

  • Controls 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

Best SQL Queries 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.