POST_START
# Using the Catalog.Schema.Object Three-Level Namespace in Databricks Unity Catalog
## PRIMARY OPERATION: `USE CATALOG training;`
The Unity Catalog in Databricks provides a three-level namespace structure: `Catalog.Schema.Object`. This structure allows you to organize and manage your data assets in a hierarchical and secure manner.
The **primary operation** in this lesson is to **use the catalog** named `training`. This is the top-level namespace in the Unity Catalog hierarchy.
—
## Step 1: Use the Training Catalog
To begin, you need to switch the current context to the `training` catalog. This is done using the following SQL command:
“`sql
USE CATALOG training;
“`
This command sets the default catalog for subsequent operations, such as querying tables or creating objects.
—
## Step 2: Use the Sales Schema (Optional but Recommended)
After using the catalog, you may optionally switch to a schema within that catalog. For example, to use the `sales` schema:
“`sql
USE SCHEMA sales;
“`
This command sets the default schema for subsequent operations, making it easier to reference objects within that schema.
—
## Step 3: Query the Customers Table
Now that you are in the `training` catalog, you can query objects within it. For example, to select all data from the `customers` table in the `sales` schema, you can use:
“`sql
SELECT * FROM sales.customers;
“`
This query retrieves all rows and columns from the `customers` table located in the `sales` schema of the `training` catalog.
—
## Step 4: Query the Customers Table Using the Full Three-Level Namespace
Alternatively, you can reference the `customers` table using the full three-level namespace directly, without switching schemas or catalogs first:
“`sql
SELECT * FROM training.sales.customers;
“`
This query explicitly references the `customers` table in the `sales` schema of the `training` catalog, providing clarity and precision in your SQL statements.
—
## Summary
In this lesson, you've learned how to use the three-level namespace in Unity Catalog: `Catalog.Schema.Object`.
– You used the `training` catalog.
– You optionally used the `sales` schema.
– You queried the `customers` table using both the schema-qualified and fully qualified namespace.
This structure helps you organize your data assets, improve security, and ensure clarity in your data workflows.


Leave a Reply