cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create temporary table in databricks

mano7438
New Contributor III

Hi Team,

I have a requirement where I need to create temporary table not temporary view.

Can you tell me how to create temporary table in data bricks ?

4 REPLIES 4

Kaniz
Community Manager
Community Manager

Hi @mano7438In Databricks, you can create a temporary table using the CREATE TEMPORARY TABLE statement. However, this functionality is only available in Delta Live Tables.

Sources:
- [Docs: publish](https://docs.databricks.com/delta-live-tables/publish.html)
- [Docs: sql-ref](https://docs.databricks.com/delta-live-tables/sql-ref.html)

StephanieRivera
Valued Contributor II
Valued Contributor II

Can you share why you want a table instead of a view? I use createOrReplaceGlobalTempView if I need my temp view in other notebooks.

https://spark.apache.org/docs/3.1.1/api/python/reference/api/pyspark.sql.DataFrame.createGlobalTempV...

NandiniN
Valued Contributor II
Valued Contributor II

Hi mano7438,

CREATE TEMPORARY TABLE my_table
USING <CSV>
OPTIONS (
 path 'dbfs:/<path-to-your-file>/file.tsv',
 delimiter '\t',
 header 'true'
)

or 

CREATE TEMPORARY TABLE temp_table (id int) using parquet;

Note: CREATE TEMPORARY TABLE without a provider is not allowed.

Thanks!

NandiniN
Valued Contributor II
Valued Contributor II

I just learnt, the above is a LEGACY support and hence must not be used. This isn't supported syntax, so there would be a lot of restrictions on the usage of this.

Internally it is just a view and hence we should go for create temp view instead. 

I know your question was sometime back(so for newer visits to this query), I would like to understand, are you wanting to migrate and it blocks you somehow?

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.