A view, or virtual table, can be defined as an alternate way of collecting data from one or more tables in a database. Thus, the view consists of rows and columns just like a normal table that is generated dynamically when a query is executed. It, however, does not actually exist as a stored set of data in the database.
Views are useful for the following purposes:
- To restrict a user to specific rows in a table.
- To restrict a user to specific columns.
- To join columns from multiple tables so that they appear to be a single table.
- To get aggregate information instead of supplying details.
Views are generally used to:
Focus on Specific Data
Views allow users to focus only on data that interests them, rather than viewing all of the data in the table. Thus it can be said that views provide a security mechanism for the data in the table.
Simplify Data Manipulation
Views also help in simplifying the data manipulation. Queries, joins, and projections that are used frequently can be defined as views. This helps in keeping the user from having to specify the conditions every time an operation is performed on the data.
Views help users to customize data by allowing them to view the data in different ways. This helps primarily when different users use the data concurrently.
Export and Import Data
Views allow the user to export and import data to and from other applications.
Combine Partitioned Data
We can combine the results of two or more queries by using the T-SQL union operator within a view.