Chapter 12. Views
Well-designed applications generally expose a public interface while keeping implementation details private, which insulates end users from complexity and future changes. With Snowflake, you can store data in tables but provide access to that data through a set of views (and/or table functions, which are covered in Chapter 17). This chapter discusses what views are, how they are created, and when and how you might want to use them.
What Is a View?
A view is a database object similar to a table, but views can only be queried. Views do not involve any data storage (with the exception of materialized views, which are discussed later). One way to think of a view is as a named query, stored in the database for easy use. If you run a report on the last business day of each month, you could create a view containing the query used to generate the report, and then query the view each month. This is just one of several uses of views, some of which will be discussed later in the chapter.
Creating Views
Views are created using the create view
statement, which is essentially a name followed by a query. Here’s a simple example of a view that includes four columns from the Employee
table:
PUBLIC>create view employee_vw as select empid, emp_name, mgr_empid, inactive from employee;
+----------------------------------------+ | status | |----------------------------------------| | View EMPLOYEE_VW successfully created. | ...
Get Learning Snowflake SQL and Scripting now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.