Prepstellar

DP-750 · Unity Catalog Objects and Discovery

22 cards

Unity Catalog Tables, Views, and Materialized Views

Swipe, scroll or use ← →
  1. Pick the object before you write the DDL

    Unity Catalog gives you four ways to put a result in front of your users, and they differ on one question: who stores the rows, and when does the query run? Choosing wrongly is rarely a syntax error. It shows up weeks later as a stale dashboard, a table duplicated once per audience, or storage nobody remembers to clean up.

    Object What it holds When the query runs
    Managed table The data itself, with files managed by Azure Databricks Never: the rows are already stored
    Standard view A stored query, no rows On every access
    Dynamic view A stored query plus user-aware filters and masks On every access, evaluated for the caller
    Materialized view A cached result, stored as a Delta table At refresh time, not at read time

    Work down that table as three questions in order: does the object own data, does it recompute on read, and does its answer change per user.

    1 / 22
  2. Quick check

    A team is deciding between a managed table and a standard view for the same sales data. Which statement separates the two correctly?

    1. AA managed table recalculates its rows each time someone reads it

      Recomputing on read is view behavior. A managed table already holds its rows, so nothing is recalculated when it is queried.

    2. BA managed table owns the stored rows; a view stores only its query

      Right. The table persists the data while the view persists only the query that produces a result.

    3. CA standard view owns the data files and the managed table owns the query

      This reverses both objects: the view is the one that keeps a query, and the table is the one with files behind it.

    2 / 22

  3. Persist data with a managed table

    A managed table persists data for long-term storage and is the default table type in Unity Catalog. Azure Databricks manages both its metadata and its underlying data files, which is why managed tables also receive integrated storage optimization and lifecycle management.

    Create one with CREATE TABLE and column definitions. Managed tables use Delta Lake by default, so they arrive with ACID transactions, time travel, and schema enforcement already in place.

    CREATE TABLE production.sales.sales_transactions (
      transaction_id BIGINT,
      customer_id INT,
      product_name STRING,
      amount DECIMAL(10,2),
      transaction_date DATE
    );
    

    Because Azure Databricks owns the storage lifecycle, dropping a managed table removes both its metadata and its data files. That is deliberate: it stops managed data from being orphaned in storage after the object disappears from the catalog.

    3 / 22
  4. Persist data with a managed table

    Unity Catalog names objects in three levels, so a table is addressed as catalog.schema.table. You can spell that out on every statement, or establish the current catalog and schema first with USE CATALOG and USE SCHEMA and then use the short table name.

    USE CATALOG production;
    USE SCHEMA sales;
    
    CREATE TABLE sales_transactions (
      transaction_id BIGINT,
      customer_id INT,
      amount DECIMAL(10,2)
    );
    

    Both forms produce the same object. The context statements supply the first two levels of the name; they do not remove the requirement that all three levels exist. There is no two-level shortcut that skips the schema, and no USE TABLE that would set the context for you.

    4 / 22
  5. Quick check

    You run USE CATALOG and USE SCHEMA, then create a table. How can that table be addressed afterwards, and what happens if it is dropped?

    1. ABy its short name; dropping it removes metadata and data files

      Right. The current catalog and schema supply the first two name levels, and a managed table's drop clears both its metadata and its files.

    2. BBy a two-level catalog and table name; dropping it keeps the files in place

      The namespace always has three levels, so a name that omits the schema does not identify the table, and a managed drop does delete the files.

    3. CBy its storage path only; dropping it leaves the metadata registered

      A managed table is addressed by name rather than by path, and its drop removes the catalog metadata as well.

    5 / 22

  6. Document rules with constraints and generated columns

    Reach for constraints and generated columns when the table definition itself should carry the rules, instead of leaving them in whatever pipeline happens to write the data. A generated column computes its value from other columns, and CHECK and NOT NULL constraints enforce data-quality rules at write time.

    CREATE TABLE customer_orders (
      order_id BIGINT NOT NULL,
      customer_email STRING NOT NULL,
      order_total DECIMAL(10,2),
      tax_amount DECIMAL(10,2) GENERATED ALWAYS AS (order_total * 0.08),
      CONSTRAINT valid_total CHECK (order_total > 0)
    );
    

    Here the tax never has to be supplied by the loader, and an order with a total of zero never lands.

    6 / 22
  7. Document rules with constraints and generated columns

    Primary-key and foreign-key constraints behave differently. They document relationships but are informational: they do not enforce referential integrity at write time. Their value is descriptive and analytical, since they record the data model and let the query optimizer make better join decisions.

    Constraint Enforced on write? What it buys you
    NOT NULL Yes Rejects rows with a missing value
    CHECK Yes Rejects rows that break the rule
    PRIMARY KEY No Records the identifying column or columns
    FOREIGN KEY No Records the relationship to another table

    Constraints can be declared inside CREATE TABLE or added later with ALTER TABLE. Either way, the enforced and informational halves of that table keep their separate meanings.

    7 / 22
  8. Quick check

    An order table has a CHECK constraint on its total and a foreign key to the customer table. A write satisfies the CHECK but points to a customer that does not exist. What happens?

    1. AIt is rejected, because both kinds of constraint block invalid writes

      Only some constraints are enforced. CHECK and NOT NULL reject bad rows, but key constraints do not.

    2. BIt is rejected, because a foreign key is validated before the CHECK runs

      There is no validation order to appeal to here: the foreign key is never checked at write time in the first place.

    3. CIt is accepted, because the key constraint documents but does not enforce

      Right. Foreign keys are informational metadata for modeling and optimization, so the row is written even though the reference is dangling.

    8 / 22

  9. Keep your progress in the app

    That’s 3 of 8 quick checks. In the app they stay answered, and every lesson remembers where you left off.

  10. Create a standard view

    A standard view stores a query rather than table data. Create it with CREATE VIEW followed by a SELECT query, and the view then behaves as a virtual table that any consumer can select from.

    CREATE VIEW customer_order_summary AS
    SELECT
      c.customer_id,
      c.customer_name,
      c.region,
      COUNT(o.order_id) AS total_orders,
      SUM(o.order_total) AS total_spent
    FROM customers c
    INNER JOIN orders o ON c.customer_id = o.customer_id
    GROUP BY c.customer_id, c.customer_name, c.region;
    

    The query runs whenever the view is accessed, so changes in the underlying tables appear automatically in its results. Nobody has to remember to refresh anything.

    9 / 22
  11. Create a standard view

    That on-demand behavior is what makes a standard view suitable for simplifying joins, encapsulating business logic, or presenting a consistent interface when current data matters. It is also the source of its one real weakness: complex joins and aggregations can make a standard view slow, because they are recomputed for each access.

    You want Standard view verdict
    Always-current results Ideal, since it recalculates on read
    A shared definition of a join or a metric Ideal, and there is no copy to keep in sync
    A heavy aggregation read hundreds of times a day Costly, since every reader pays for the computation

    Views can also be layered on top of other views to break complex logic into readable pieces, but too many layers make troubleshooting harder and hide where the time is going.

    10 / 22
  12. Quick check

    A view joins three tables that are updated all day, and analysts must always see the latest rows. What does a standard view give them, and at what price?

    1. ACurrent results, since its query runs on each access and is recomputed

      Right. Recomputation on every access is exactly what keeps the result current, and it is also what the analysts pay for in query time.

    2. BCached results that stay fixed between scheduled refreshes of the stored copy

      Caching between refreshes describes a materialized view, which is precisely the freshness trade this team refused.

    3. CCurrent results at no compute cost, because rows are copied into the view ahead of time

      A standard view stores no rows, so there is no copy to read from and the computation cannot be avoided.

    11 / 22

  13. Vary what each user sees with a dynamic view

    A dynamic view adds row filters or column masks that depend on the querying user. It is still a view, so it still runs its defining query on access, but a conditional expression decides what that user is allowed to see.

    Column masking uses a CASE expression together with is_account_group_member():

    CREATE VIEW sales_redacted AS
    SELECT
      user_id,
      CASE WHEN is_account_group_member('auditors') THEN email
           ELSE 'REDACTED'
      END AS email,
      country_region,
      product,
      total
    FROM sales_raw;
    

    One object now answers two audiences differently, and neither of them needs its own copy of the data.

    12 / 22
  14. Vary what each user sees with a dynamic view

    Row-level filtering follows the same pattern, moving the condition into the WHERE clause:

    CREATE VIEW sales_filtered AS
    SELECT user_id, country_region, product, total
    FROM sales_raw
    WHERE CASE
            WHEN is_account_group_member('managers') THEN TRUE
            ELSE total <= 1000000
          END;
    

    The payoff is organizational rather than technical: a dynamic view can centralize fine-grained access logic without duplicating a table for each audience. The alternative is a separate table or view per access level, with every one of them to maintain, refresh, and audit separately.

    13 / 22
  15. Quick check

    Auditors must see raw email addresses, everyone else must see redacted values, analysts need current rows, and nobody will maintain one table per audience. Which object fits?

    1. AA standard view returning the email column unchanged to all

      An unchanged projection shows the same address to auditors and to everyone else, so no masking happens at all.

    2. BA dynamic view whose column mask depends on the querying user

      Right. The mask is evaluated against the caller's group membership, and a single view keeps current data with no duplicated copies.

    3. COne managed table per audience, each with its own copy of the rows

      Copying the rows per audience is the duplication the team ruled out, and it scatters the access logic across several objects.

    14 / 22

  16. Cache expensive results with a materialized view

    A materialized view precomputes and caches query results as a Delta table. Create it with CREATE MATERIALIZED VIEW followed by its defining query, and it then returns cached results instead of recalculating the full query on every access.

    CREATE MATERIALIZED VIEW daily_sales_summary AS
    SELECT
      transaction_date,
      COUNT(*) AS transaction_count,
      SUM(amount) AS total_sales,
      AVG(amount) AS average_sale
    FROM sales_transactions
    GROUP BY transaction_date;
    

    The object is created as a view, but unlike a standard view it has stored output behind it. That is what makes it fast, and also what makes its result a snapshot of the last refresh rather than of this instant.

    15 / 22
  17. Cache expensive results with a materialized view

    A materialized view is therefore a strong fit for frequently accessed, expensive aggregations when eventual consistency is acceptable. A standard view is the better fit when the result must reflect source changes immediately.

    Requirement Choose Why
    Heavy aggregation, many readers, small lag tolerated Materialized view The computation happens once per refresh, not once per reader
    Result must reflect a write that just happened Standard view It recalculates on access, so nothing can be stale
    Different results per user Dynamic view Access logic is evaluated for the caller

    The deciding question is not which object is faster. It is how much staleness the business question can absorb.

    16 / 22
  18. Quick check

    A dashboard runs the same expensive aggregation for hundreds of users, and a short lag behind source changes is acceptable. Which object fits, and why?

    1. AA standard view, because it never repeats the aggregation work

      A standard view repeats the aggregation on every access, so hundreds of readers means hundreds of executions.

    2. BA dynamic view, because caching is a form of user-level filtering

      A dynamic view addresses who may see which rows; it does not accelerate a repeated aggregation.

    3. CA materialized view, because it serves a cached result

      Right. The cost is paid once per refresh and every reader is served from the cached result, which the accepted lag allows.

    17 / 22

  19. Keep the cache current

    A cached result is only useful while it is close enough to the source. Refresh a materialized view manually, on a schedule, or when upstream data changes, so the cached result incorporates those source changes. A schedule can be declared with the view itself:

    CREATE MATERIALIZED VIEW daily_sales_summary
    SCHEDULE EVERY 1 DAY
    AS
    SELECT transaction_date, COUNT(*) AS transaction_count, SUM(amount) AS total_sales
    FROM sales_transactions
    GROUP BY transaction_date;
    

    Match the interval to the question being asked. A daily sales summary read each morning does not need an hourly rebuild, and an hourly operational metric is not served by a nightly one.

    18 / 22
  20. Keep the cache current

    Materialized views support incremental and full refresh strategies. Incremental refresh processes changed data instead of reprocessing the complete result, which is dramatically cheaper on a large source. It carries a prerequisite: its source tables must be Delta tables with row tracking enabled, because that is how the changed rows are identified.

    ALTER TABLE sales_transactions
    SET TBLPROPERTIES (delta.enableRowTracking = true);
    

    Without row tracking, the refresh has no way to tell which rows moved and falls back to reprocessing everything. Informational primary keys do not substitute for it, and neither does a mask or a filter on the source: those govern visibility, not change detection.

    19 / 22
  21. Quick check

    An incremental refresh of a materialized view cannot start. The source tables are Delta tables, but the refresh keeps reprocessing everything. What is missing?

    1. AInformational primary keys on the sources

      Key constraints are informational metadata about relationships and say nothing about which rows changed.

    2. BColumn masks on the source columns

      Masks control which values a user can see and have no role in detecting changed data.

    3. CRow tracking enabled on the Delta source tables

      Right. Incremental refresh identifies changed rows through row tracking, so a Delta source without it cannot be processed incrementally.

    20 / 22

  22. Key takeaways

    • Use a managed table to persist data while Azure Databricks manages metadata and files. Create it with CREATE TABLE, address it as catalog.schema.table or through USE CATALOG and USE SCHEMA, and remember that dropping it removes both metadata and files.
    • Delta Lake is the default format for managed tables, which is what brings ACID transactions, time travel, and schema enforcement.
    • CHECK and NOT NULL enforce data-quality rules and a generated column derives its value from other columns, while primary and foreign keys are informational and document relationships without enforcing them.
    • Use a standard view for an on-demand query result that reflects current source data, and accept that complex joins and aggregations are recomputed on each access.
    • Use a dynamic view to apply user-dependent row filters or column masks, centralizing access logic instead of duplicating a table per audience.
    • Use a materialized view to cache expensive query results and refresh them manually, on a schedule, or on upstream change. Enable row tracking on Delta source tables so incremental refresh can process only what changed.
    21 / 22
  23. Quick check

    Which summary matches each object to the behavior that defines it?

    1. AManaged tables cache query output, dynamic views own the data files, and materialized views recompute on every access

      Every pairing here is misplaced: caching belongs to the materialized view, file ownership to the managed table, and recomputation to the standard view.

    2. BManaged tables own data, dynamic views vary results per user, and materialized views cache results

      Right. Persistent storage, per-user evaluation, and cached output are the three defining behaviors.

    3. CManaged tables store queries, and both view types enforce keys

      A managed table stores rows rather than a query, and no view type enforces key constraints, which are informational everywhere in Unity Catalog.

    22 / 22

  24. 8 quick checks · then the test

    In the app, finishing the quick checks opens this lesson’s 10-question test, and the ones you miss come back exactly when you’re about to forget them.

The whole course, on your phone

Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.