How to create temporary table in Azure Databricks SQL

Temporary tables required when we are processing complex data using sql(structured query language). Temporary tables help us to store data temporarily into the session and once we are done with them either we can drop them manually or once session is closed then these tables will be drop automatically.

Unfortunately there are many complication in creating temporary tables as we are dealing with big data with replication at different places for backup and redundancy. Hence temporary tables can’t be created in Databricks right now. However Databricks provide temporary views to handle such dataset but with limited functionality which we have using temporary tables.

In Databricks we will be using Temporary view in place of Temporary tables, like Microsoft SQL or MySQL Databricks provide view object which stores definition of the sql script. However in Databricks we can create Temporary Views in addition to the Permanent views.

Now let see how we can create temporary views in Databricks.

CREATE TEMPORARY VIEW [tempViewName]
as
SELECT CURRENT_DATE AS Date

Now in above example we have created a view by selecting current date and renaming the column name as Date. The tempView will have one date type column along with the data of one row and the row will have current date as value.

In similar fashion if we want to use some data from a actual table then we can modify the above syntax according to our need. For example:

CREATE TEMPORARY VIEW [tempViewName]
as
SELECT column1, column2, column3, ....... FROM [tableName]

Read More

https://databricks-tutorials.thesoft.in/how-to-register-for-databricks-community-edition/