cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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 ]

User16869510359
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.

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.