Databricks Lab & Excercise – Notebook – Unity Catalog → schema → table

let’s make this a “Databricks SQL Quickstart – 25 Commands” guide for first-time use in the Notebook with the Unity Catalog → schema → table workflow.

I’ll order these so you can start from catalog exploration, work with schemas & tables, and query & manage data — exactly how you’d try things in a fresh Databricks SQL-enabled environment.


Part 1 – Catalog & Schema Exploration (1–7)

-- 1. List all catalogs
SHOW CATALOGS;

-- 2. Switch to a specific catalog
USE CATALOG main;

-- 3. Show schemas in the current catalog
SHOW SCHEMAS;

-- 4. Switch to a specific schema (database)
USE SCHEMA default;

-- 5. Show all tables in current schema
SHOW TABLES;

-- 6. Show current catalog and schema
SELECT current_catalog(), current_schema();

-- 7. Describe schema details
DESCRIBE SCHEMA EXTENDED default;

Part 2 – Table Exploration & Metadata (8–12)

-- 8. Describe a specific table
DESCRIBE TABLE my_table;

-- 9. Show extended metadata for a table
DESCRIBE TABLE EXTENDED my_table;

-- 10. Show columns of a table
SHOW COLUMNS IN my_table;

-- 11. Get table history (with Unity Catalog)
DESCRIBE HISTORY my_table;

-- 12. Preview table data
SELECT * FROM my_table LIMIT 10;

Part 3 – Table Creation & Data Insertion (13–17)

-- 13. Create a managed table
CREATE TABLE sales (
    id INT,
    product STRING,
    quantity INT,
    price DOUBLE
);

-- 14. Insert sample rows
INSERT INTO sales VALUES
(1, 'Laptop', 2, 800.00),
(2, 'Mouse', 5, 20.50),
(3, 'Keyboard', 3, 45.99);

-- 15. Create an external table (from a path)
CREATE TABLE ext_sales
USING PARQUET
LOCATION 'dbfs:/mnt/data/sales/';

-- 16. Create a table from query results
CREATE TABLE top_sales AS
SELECT * FROM sales WHERE quantity > 2;

-- 17. Overwrite a table with new data
INSERT OVERWRITE sales VALUES
(10, 'Monitor', 4, 150.00);

Part 4 – Querying & Filtering Data (18–22)

-- 18. Select specific columns
SELECT product, price FROM sales;

-- 19. Filter with WHERE
SELECT * FROM sales WHERE price > 50;

-- 20. Aggregate with GROUP BY
SELECT product, SUM(quantity) AS total_qty
FROM sales
GROUP BY product;

-- 21. Sort results
SELECT * FROM sales ORDER BY price DESC;

-- 22. Use LIMIT
SELECT * FROM sales ORDER BY quantity DESC LIMIT 5;

Part 5 – Maintenance & Management (23–25)

-- 23. Drop a table
DROP TABLE IF EXISTS top_sales;

-- 24. Rename a table
ALTER TABLE sales RENAME TO sales_data;

-- 25. Optimize a table for performance (Delta table)
OPTIMIZE sales_data;

Extra Notebook Tips

  • In Databricks, prefix a cell with %sql to run SQL in a Python notebook.
  • If your table is Unity Catalog-managed, you’ll use catalog.schema.table format (e.g., main.default.sales).
  • For interactive tables, use display() in a %python cell after running a %sql query.

Related Posts

Complete DevOps Engineer Salary Roadmap for Beginners

Introduction The demand for skilled professionals who can bridge the gap between development and operations has never been higher. As businesses transition from legacy systems to cloud-native…

Read More

Complete DevOps Certification Roadmap For Strategic Career Progression

Introduction The global tech landscape is moving fast, and modern infrastructure is moving even faster. Monolithic, slow-moving systems are dead. Today, business agility depends entirely on distributed…

Read More

Transforming Enterprise Analytics with Continuous Automation in DataOps Pipelines

Introduction In modern data engineering, managing data movement manually is no longer sustainable. Organizations handle massive volumes of data arriving from applications, IoT devices, third-party APIs, and…

Read More

CI/CD in DataOps Explained for Beginners: Building Reliable Data Pipelines

Introduction In modern enterprise environments, data is no longer a static asset tucked away in a backup server. It is a live, rapidly flowing resource that fuels…

Read More

Understanding the DataOps Lifecycle Step by Step for Modern Data Teams

Introduction A structured approach to the data lifecycle is the foundation of any high-performing modern organization. When data moves from raw collection to final reporting without a…

Read More

Canada Immigration Points Calculator: Deep Dive Into the CRS Score System

Moving to a new country is a life-changing decision that brings a wave of excitement, hope, and new opportunities. For thousands of skilled professionals, healthcare workers, and…

Read More

Leave a Reply