cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

temp tables in Databricks

AMadan
New Contributor II

Hey Team,

We are in a migration phase from SQL server to Databricks.

In our sql server databricks, lot of times, #temp tables created and dropped like typical Datawarehousing sql.

In Databricks, we can do 2 things. I want to check which one is best approach and why?

1) create temp views in databricks and make use of views later in the query

2) create delta table with temp(prefix) and make use of temp table and at the end drop temp table.


I am looking forward for your response.

2 REPLIES 2

Kaniz_Fatma
Community Manager
Community Manager

Hi @AMadan

โ€ข The best approach for migrating from SQL Server to Databricks depends on specific requirements and use cases.


โ€ข Considerations for each approach:


  - Creating Temp Views:
     โ€ข Temp views in Databricks are similar to temporary tables in SQL Server
     โ€ข Temp views do not persist and are only available for the duration of the Databricks session
     โ€ข Can be used in subsequent queries like regular tables
     โ€ข Useful for ad hoc analysis or temporary transformations
     โ€ข Good approach for complex transformations or multiple queries referencing the same temporary data


  - Creating Delta Tables:
     โ€ข Delta tables in Databricks provide ACID transactions, time travel, and optimized query performance
     โ€ข Delta tables are persisted and can be used across Databricks sessions
     โ€ข Useful for storing and managing intermediate or temporary data that needs to be reused or accessed multiple times
     โ€ข Provide more flexibility and control over the data compared to temp views
     โ€ข Good approach for complex transformations or multiple queries referencing the same temporary data


โ€ข Choice between temp views and delta tables depends on specific requirements and use cases
โ€ข Temp views are suitable for ad hoc analysis or temporary transformations
โ€ข Delta tables offer more control and flexibility over temporary data

berserkersap
Contributor

Just to add a bit more from experience

If you are doing to use the temp tables too many times, then using temp views is going to slow down your cluster . It is due to lazy evaluation unless you persist that view (dataframe cache or globaltempview).

Every time your temp view is called, it will execute the view definition/code. This also depends upon your cluster capacity, how complex the view definition is, how much data the temp view has.

Please correct me if I am wrong.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!