Database Views
In this chapter you will learn what a database view is and its importance in SQL programming. In addition, you will be able to perform the existing SQL commands in creating, updating and dropping views.
Defining Views
A view is a database object formed when your SELECT queries are saved in the database for future use. This means that a view exists because of the tables where its data values were derived from. Thus, one or more tables can create a database view. Also, it has the same characteristics similar to the actual table except that you don’t need some physical space to store it (temporarily saved in the computer’s memory). Moreover, being a virtual table, you cannot modify its data values.
When executing a SELECT statement to create the view, you can either get the column names from a particular table or perform certain functions and calculations that will manipulate the given data values. Once created, these views can perform any of the following tasks:
• Simplify data retrieval - Some end users may not have the knowledge to perform database operations to get the query result they need. So to make things easier, you can create different views from the tables that users require.
• Implement database security – There are times that you have to restrict certain users on what they can access from your database, whether they are allowed to modify data or just view information. To ensure that the tables are secured, you can generate views that only display the data values that you allow users to access.
• Support data summarization and report generation – Through views, you are able to turn a complicated SELECT query into a simple summarized data that you can generate from multiple tables. This summary or report could be generated and updated from time to time. That is why instead of composing complex programming lines you can just use aggregate functions incorporated in the creation of views.