Creating and Inspecting Managed Tables

POST_START
# Creating and Inspecting Managed Tables in Databricks Unity Catalog

In this lesson, you will learn how to create and inspect managed tables in Databricks using Unity Catalog. We will focus on the `CREATE TABLE` operation and demonstrate how to verify and understand the structure of the created table.

## Step 1: Create a Managed Table

We begin by creating a managed table named `customers` in the `training.sales` schema. The table will store customer information including customer ID, name, country, email, and creation timestamp.

“`sql
CREATE TABLE training.sales.customers (
customer_id BIGINT,
customer_name STRING,
country STRING,
email STRING,
created_at TIMESTAMP
);
“`

This command creates a new managed table in Unity Catalog. The table is stored in the `training.sales` schema and is automatically managed by Databricks, including lifecycle and access control.

## Step 2: Verify the Table Exists

After creating the table, you can verify that it exists in the specified schema using the `SHOW TABLES` command.

“`sql
SHOW TABLES IN training.sales;
“`

This command returns a list of all tables in the `training.sales` schema, allowing you to confirm that your `customers` table has been successfully created.

## Step 3: Inspect the Table Structure

To understand the structure of the table, use the `DESCRIBE TABLE` command. This provides metadata such as column names, data types, and other relevant information.

“`sql
DESCRIBE TABLE training.sales.customers;
“`

The output will display the column names, data types, and other properties of the `customers` table, helping you confirm that the table was created as expected.

## Step 4: Get Extended Table Information

For more detailed information about the table, including location, comment, and other properties, you can use the `DESCRIBE TABLE EXTENDED` command.

“`sql
DESCRIBE TABLE EXTENDED training.sales.customers;
“`

This command provides a richer set of metadata, which is useful for understanding how the table is stored and configured within Unity Catalog.

## Step 5: Retrieve the CREATE TABLE Statement

If you want to see the exact DDL (Data Definition Language) used to create the table, you can use the `SHOW CREATE TABLE` command.

“`sql
SHOW CREATE TABLE training.sales.customers;
“`

This command returns the full SQL statement used to create the table, which can be useful for replication or documentation purposes.

## Summary

In this tutorial, you have learned how to:

1. Create a managed table in Databricks Unity Catalog using the `CREATE TABLE` command.
2. Verify the existence of the table using `SHOW TABLES`.
3. Inspect the table structure using `DESCRIBE TABLE`.
4. Retrieve extended table information with `DESCRIBE TABLE EXTENDED`.
5. Obtain the exact DDL used to create the table using `SHOW CREATE TABLE`.

These commands are essential for working with managed tables in Unity Catalog and are commonly used during development, validation, and documentation phases.

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies and similar technologies to enhance your experience on wobizdu.com, analyze site traffic, personalize content, and deliver relevant ads. Some cookies are essential for the site to function, while others help us improve performance and user experience. You may accept all cookies, decline optional ones, or customize your settings. Review our Privacy Policy to learn more.