Over the past several tutorials, we have focused on various approaches to querying. Let's take a break from that branch of SQL and come back to DDL. In this tutorial, we will discuss the purpose of Views, when to use them, and why you should understand them as a data professional. This tutorial will cover the following learning objectives:
Before we get into how to create views, we need to understand the difference between views and tables. Watch the following videos to get a better understanding of this concept:
Views are one of the most helpful tools when working with complex queries. But, when should you use them? Watch the following video to get a better understanding of this concept:
SELECT *
FROM [view_name];
Now that you have a clear understanding of how a View differs from a table and when to use views, let's take a look at how to create Views. Watch the following video to get a better understanding of this concept:
CREATE VIEW
command is pretty straightforward.
To create a basic view, use the following syntax:
CREATE VIEW [view_name] AS [query];
Once you have started creating Views, it can be easy to get carried away by creating too many views. Thus, there are some industry best practices to prevent this from happening. Read the following article to get a better understanding of this concept:
WITH
Clause of the
SELECT
command instead of creating a seldom-used view." (docs.vmware.com, 2023)
WHERE
conditions
while other WHERE
conditions work well." (docs.vmware.com, 2023)
Congratulations! You just completed the Views Tutorial! To help test your knowledge, let's
practice by creating some basic views. This exercise is based on the exercise of
the previous tutorial.
**It's highly recommended that you
complete the exercise outlined in the previous tutorial before beginning this exercise.**
Have any issues with the above exercise? Post your question on Discord!