cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

If exists in databrickds sql

g96g
New Contributor III

what is the equivalent of "IF EXISTS" in databricks? I would like to first check something later after that use the insert into statement.

1 ACCEPTED SOLUTION

Accepted Solutions

Ajay-Pandey
Esteemed Contributor III

Hi @Givi Saluโ€‹ ,

IF EXISTS - If specified, no TABLE_OR_VIEW_NOT_FOUND error is thrown when the table does not exist.

DROP TABLE IF EXISTS employeetable;

View solution in original post

4 REPLIES 4

Ajay-Pandey
Esteemed Contributor III

Hi @Givi Saluโ€‹ ,

IF EXISTS - If specified, no TABLE_OR_VIEW_NOT_FOUND error is thrown when the table does not exist.

DROP TABLE IF EXISTS employeetable;

Anonymous
Not applicable

Hi @Givi Saluโ€‹ 

We haven't heard from you since the last response from @Ajay Pandeyโ€‹ โ€‹, and I was checking back to see if her suggestions helped you.

Or else, If you have any solution, please share it with the community, as it can be helpful to others. 

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

WWoman
New Contributor II

Is there a way to check if a table exists, without trying to drop it? something like :

select table_name from system_catalogs where database_name = 'mydb' and schema_name = 'myschema' and object_name = 'mytab';

kottsane
New Contributor II
New Contributor II

You can query `system.information_schema.tables` which includes all existing tables in the metastore. More on information schema: https://docs.databricks.com/en/sql/language-manual/sql-ref-information-schema.html

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.