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:ย 

Database within a Database in Databricks

User16790091296
Contributor II

Is it possible to have a folder or database with a database in Azure Databricks? I know you can use the "create database if not exists xxx" to get a database, but I want to have folders within that database where I can put tables.

2 REPLIES 2

Ryan_Chynoweth
Honored Contributor III

I think that you are looking to provide a "LOCATION" for your database on DBFS. When you provide a location for your database all the tables will be created within that folder by default.

See a create table example below:

CREATE TABLE [ IF NOT EXISTS ] table_identifier
  [ ( col_name1 col_type1 [ COMMENT col_comment1 ], ... ) ]
  USING data_source
  [ OPTIONS ( key1 [ = ] val1, key2 [ = ] val2, ... ) ]
  [ PARTITIONED BY ( col_name1, col_name2, ... ) ]
  [ CLUSTERED BY ( col_name3, col_name4, ... )
      [ SORTED BY ( col_name [ ASC | DESC ], ... ) ]
      INTO num_buckets BUCKETS ]
  [ LOCATION path ]
  [ COMMENT table_comment ]
  [ TBLPROPERTIES ( key1 [ = ] val1, key2 [ = ] val2, ... ) ]
  [ AS select_statement ]

brickster_2018
Esteemed Contributor
Esteemed Contributor

The default location of a database will be in the /user/hive/warehouse/<databasename.db>. Irrespective of the location of the database the tables in the database can have different locations and they can be specified at the time of creation.

Database location and Table location are independent. A table can be created in any location. So to answer your question, it's possible to create a sub-directory and create tables in that.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!