Use Database


USE statement is used to set the current database. Once set, the unqualified database artifacts such as tables, functions and views that are referenced by SQLs are resolved from the current database


The default database name is ‘default’


USE database_name


database_name Name of the database will be used. If the database does not exist, an exception will be thrown.


-- Use the 'userdb' which exists.
USE userdb;
| Result  |

-- Use the 'userdb1' which doesn't exist
USE userdb1;
Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;(state=,code=0)

Did this page help you?