POST_START
Creating, Inspecting, and Managing Schemas in Unity Catalog
I recently needed to set up a new schema in Unity Catalog for a sales team to store their data. I started by creating the schema if it didn’t already exist, using the CREATE SCHEMA IF NOT EXISTS command.
CREATE SCHEMA IF NOT EXISTS training.sales;
I saw a representative result like this:
Command completed successfully; the requested catalog state change is now in effect.
I checked to make sure the schema was created by listing all schemas in the training catalog. I used the SHOW SCHEMAS IN training command to confirm the new schema was present.
SHOW SCHEMAS IN training;
I saw a representative result like this:
| databaseName |
|---|
| default |
| sales |
| finance |
I then wanted to inspect the schema details to verify its properties. I used the DESCRIBE SCHEMA training.sales command to get more information about the schema.
DESCRIBE SCHEMA training.sales;
I saw a representative result like this:
| info_name | info_value |
|---|---|
| Database Name | sales |
| Catalog Name | production |
| Owner | data_engineers |
I decided to switch to the training catalog to make it easier to work with the schema. I used the USE CATALOG training command to set the current catalog.
USE CATALOG training;
I saw a representative result like this:
Command completed successfully; the requested catalog state change is now in effect.
Next, I switched to the sales schema within the training catalog using the USE SCHEMA sales command.
USE SCHEMA sales;
I saw a representative result like this:
Command completed successfully; the requested catalog state change is now in effect.
I wanted to verify the current schema context to ensure I was working in the correct environment. I ran the SELECT current_schema() command to check the current schema.
SELECT current_schema();
I saw a representative result like this:
| customer_id | customer_name | region | status |
|---|---|---|---|
| 1001 | Maria Keller | EU | ACTIVE |
| 1002 | Daniel Smith | US | ACTIVE |
| 1003 | Sofia Rossi | EU | INACTIVE |
Later, I needed to change the owner of the schema. I used the ALTER SCHEMA training.sales SET OWNER TO `data_engineers` command to update the owner.
ALTER SCHEMA training.sales SET OWNER TO `data_engineers`;
I saw a representative result like this:
Command completed successfully; the requested catalog state change is now in effect.
Finally, I decided to clean up by dropping the schema if it was no longer needed. I used the DROP SCHEMA IF EXISTS training.sales command to remove it.
DROP SCHEMA IF EXISTS training.sales;
I saw a representative result like this:
Command completed successfully; the requested catalog state change is now in effect.


Leave a Reply