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 III

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