Now before we dive into the variety of reasons for using a view, let’s first briefly understand what a view is.
To put simply, a view is a stored single SELECT query. Generally speaking, we use views to encapsulate a query, or part of a query, for reusability.
Here are some reasons we can consider using a view for:
Hiding particular data for end users
We can use a view to hide any sensitive or unnecessary data for the end user. This can be done by limiting the number of rows seen with a WHERE clause or by only returning specific columns from the tables. Basically we can allow the end user to see what they only need to see, nothing more. This is useful for security purposes.
Sometimes the way we store data in our tables is not very meaningful for our customers or end users. Views can be used to change the way that data is presented to a more understandable value.
Often the creation of reports involve complex expensive queries that are executed frequently. Encapsulating that complex query in a view can reduce the compile time for that query.
In next week’s post, we will be going through some examples of these reasons in action!