Running through views
1. Running through views
In this screencast, we will create views and temp views in Databricks. Let's dive in and see how each plays a unique role in data management. A view in Databricks is like a saved query that acts as a table. It is persistent, meaning it is stored in your database and remains accessible across sessions. We'll create a view named medical_records from an existing table to demonstrate. In the Databricks SQL editor, type the following command. Once the command is ready, we can run the command by pressing Shift and Enter or by clicking Run. This view stores a query logic, allowing you to access this dataset repeatedly without needing to rewrite the query. To check that the view was created, you can simply type this command and run it. After we run this command, we see that the output listing medical_records is successfully visible as a view. Once created, this view will be available even after you close and reopen the Databricks session. Persistent views are perfect for reusing complex query logic or accessing data across multiple sessions. Now, let's look at temp views. Temp views are temporary objects that are only available for the current session. They're ideal for ad-hoc analysis or staging intermediate data during a pipeline. Let's create a temp view called temp_medical_records. In the SQL editor, we can type the following command.: Once the command is ready, we run it and notice the confirmation. This temp view behaves like a regular view, it only exists for the current session. If you close the session, it will be automatically dropped. To demonstrate that it functions like a regular view, type: SELECT * FROM temp_medical_records. Once we run the query, we can observe the results. While the session remains open, the temp view can be queried normally. However, it will be dropped once the session ends, freeing up any resources. In summary, use persistent views when you reuse query logic across sessions and choose temp views for quick, temporary operations that won't extend beyond the current session. Thank you for following along!2. Let's practice!
Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.