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: 

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;

Ajay Kumar Pandey

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;

Ajay Kumar Pandey

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
Contributor

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
Databricks Employee
Databricks Employee

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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group