Monday, February 11, 2013

Database Views

A view consists of a query accessible as a virtual table in a relational database. Unlike normal tables (base tables) in a relational database, a view is not form part of the physical schema. Changing the data in a table alters the data shown in subsequent results of the view. 
Advantages of views over tables:
  • Views can represent a subset of the data contained in a table
  • Views can join and simplify multiple tables into a single virtual table
  • Views can act as aggregated tables, where the database engine aggregates data (sum, average etc.) and presents the calculated results as part of the data
  • Views take very little space to store because the database contains only the definition of a view, not a copy of all the data it presents
  • Views can limit the degree of exposure of a table or tables to the outer world
Just as functions (in programming) can provide abstraction, so database users can create abstraction by using views. In another parallel with functions, database users can manipulate nested views, thus one view can aggregate data from other views.
Just as rows in a base table lack any defined ordering, rows available through a view do not appear with any default sorting. A view is a relational table, and the relational model defines a table as a set of rows. Since sets are not ordered - by definition - the rows in a view are not ordered, either. Therefore, an ORDER BY clause in the view definition is meaningless. However, sorted data can be obtained from a view, in the same way as any other table - as part of a query statement.

No comments:

Post a Comment