POST_START
# 04. Create Managed Table
In this lesson, you'll learn how to create a **managed table** in Databricks Unity Catalog. A managed table is a table that Databricks manages, including the data and metadata. When you create a managed table, Databricks handles the storage and lifecycle of the data, making it ideal for scenarios where you want to keep the data and metadata under your control.
—
## Step 1: Create a Managed Table
To create a managed table, you use the `CREATE TABLE` statement. The table will be stored in the `training.sales` schema, and it will have the following columns:
– `customer_id` of type `BIGINT`
– `customer_name` of type `STRING`
– `country` of type `STRING`
– `email` of type `STRING`
– `created_at` of type `TIMESTAMP`
Here is the exact SQL command to create the table:
“`sql
CREATE TABLE training.sales.customers (customer_id BIGINT, customer_name STRING, country STRING, email STRING, created_at TIMESTAMP);
“`
This command creates a new table named `customers` in the `training.sales` schema with the specified columns and data types.
—
## Step 2: Verify the Table Creation
After creating the table, you can verify its existence using the `SHOW TABLES` command. This command lists all tables in a given schema.
“`sql
SHOW TABLES IN training.sales;
“`
You should see `customers` in the list of tables.
—
## Step 3: Describe the Table
To view the structure of the table, including column names, data types, and other metadata, use the `DESCRIBE TABLE` command.
“`sql
DESCRIBE TABLE training.sales.customers;
“`
This will display the schema of the `customers` table.
—
## Step 4: Describe the Table with Extended Information
For more detailed information about the table, including location, comment, and other extended metadata, use the `DESCRIBE TABLE EXTENDED` command.
“`sql
DESCRIBE TABLE EXTENDED training.sales.customers;
“`
This provides a comprehensive overview of the table's properties.
—
## Step 5: View the Create Table Statement
If you want to see the exact SQL used to create the table, you can use the `SHOW CREATE TABLE` command.
“`sql
SHOW CREATE TABLE training.sales.customers;
“`
This will return the original `CREATE TABLE` statement that was used to create the `customers` table.
—
## Summary
In this lesson, you've learned how to:
– Create a managed table in Databricks Unity Catalog.
– Verify the existence of the table using `SHOW TABLES`.
– Describe the table structure using `DESCRIBE TABLE`.
– Get extended metadata using `DESCRIBE TABLE EXTENDED`.
– Retrieve the exact `CREATE TABLE` statement using `SHOW CREATE TABLE`.
These commands are essential for working with tables in Unity Catalog and help you manage your data effectively.


Leave a Reply