SQL View Explained

In a previous discussion forum, we established that Common Table Expression or CTE is a built-in function that we could use to turn a subquery into a temporary table. However, the issue with CTEs is that it creates this table in a virtual form in which it does not inherently provide additional functionalities other than simplifying the queries down and making it a lot more readable. Granted, we can query the columns inside this temporary CTE table with a simple SELECT statement below. However, this imaginary table does not really exist outside of this CTE expression, and this is where the view comes into play. View exhibits all of the benefits of CTEs with some additional added functionality and benefits. One of the biggest benefits of using a view is turning a query into a permanent table. By saving it as a view, it allows for better reusability. For example, suppose you are tasked to build a monthly recurring sales report. In that case, it will be more practical for you to save those commonly used queries into a view rather than writing those complex queries every time you update this report. In addition, suppose there is a customer financial data table that must be presented to customer service staff members. In that case, the database administrator will be able to create a non-updatable view with the sensitive data such as credit card numbers and security codes filtered out. Leaving out and presenting only those columns or rows in that original table that the customer service staff members need to perform their essential functions. This allows for better data integrity while also enhancing data security to prevent potential data breaches.

Leave a comment