{"id":770,"date":"2025-08-19T15:35:24","date_gmt":"2025-08-19T15:35:24","guid":{"rendered":"https:\/\/dataopsschool.com\/blog\/?p=770"},"modified":"2025-08-19T15:35:45","modified_gmt":"2025-08-19T15:35:45","slug":"databricks-lab-managed-vs-external-tables-undrop-with-external-location-setup","status":"publish","type":"post","link":"https:\/\/dataopsschool.com\/blog\/databricks-lab-managed-vs-external-tables-undrop-with-external-location-setup\/","title":{"rendered":"Databricks Lab &#8211; Managed vs External Tables + UNDROP (with External Location setup)"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">Databricks Unity Catalog Tutorial<\/h1>\n\n\n\n<p><strong>Managed vs External Tables + UNDROP (with External Location setup)<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction (what we\u2019ll build)<\/h2>\n\n\n\n<p>You\u2019ll learn to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create (or reuse) an <strong>external location<\/strong> for tables.<\/li>\n\n\n\n<li>Create one <strong>managed<\/strong> table and one <strong>external<\/strong> table in the same schema.<\/li>\n\n\n\n<li><strong>Inspect<\/strong> their storage locations and types.<\/li>\n\n\n\n<li><strong>DROP<\/strong> both tables and recover them using <strong>UNDROP<\/strong> (by name and by ID).\n<ul class=\"wp-block-list\">\n<li>Managed tables\u2019 data isn\u2019t deleted immediately; it\u2019s eligible for cleanup after a grace period (7\u201330 days). You can <strong>recover within 7 days<\/strong>. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Prereqs<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Unity Catalog\u2013enabled cluster.<\/li>\n\n\n\n<li>A catalog <code>Dev<\/code> and schema <code>bronze<\/code> you can write to.<\/li>\n\n\n\n<li>A storage credential already created (e.g., <code>SC_catalog_storage<\/code>).<\/li>\n\n\n\n<li>Proper permissions: <code>USE CATALOG<\/code>, <code>USE SCHEMA<\/code>, <code>CREATE TABLE<\/code>, etc.<\/li>\n\n\n\n<li>You\u2019re on Azure (paths use <strong>abfss:\/\/<\/strong>). Adjust for S3\/GCS if needed.<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s new in Databricks? (Updates &amp; Releases)<\/h2>\n\n\n\n<p>In the workspace, click <strong>? \u2192 What\u2019s new<\/strong> to see the monthly release notes (features are rolled out in stages). For reference: <strong>August 2024<\/strong> release notes pages: Azure and Databricks docs. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/release-notes\/product\/2024\/august?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/release-notes\/product\/2024\/august?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Create External Location in Databricks<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">A) Make a folder in ADLS for external tables<\/h3>\n\n\n\n<p>In your ADLS Gen2 <strong>container<\/strong> (e.g., <code>data<\/code>), create:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/ADB\/external-tables\/\n<\/code><\/pre>\n\n\n\n<p>You\u2019ll store all external table data here (the video used <code>externaltables<\/code>\u2014name doesn\u2019t matter).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">B) (If needed) Reuse or create a <strong>storage credential<\/strong><\/h3>\n\n\n\n<p>If you already have one (e.g., <code>SC_catalog_storage<\/code>), reuse it. Otherwise, create it via <strong>Catalog \u2192 Storage credentials<\/strong> (Azure Managed Identity or SAS\/Key as per your setup). Docs: <strong>Create external locations<\/strong> (Azure\/AWS). (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/connect\/unity-catalog\/cloud-storage\/external-locations?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/connect\/unity-catalog\/cloud-storage\/external-locations?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">C) Create the <strong>external location<\/strong> (UI or SQL)<\/h3>\n\n\n\n<p><strong>UI path (as in the video):<\/strong><br>Catalog \u2192 <strong>External data<\/strong> \u2192 <strong>External locations<\/strong> \u2192 <strong>Create<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Name:<\/strong> <code>ext_tables<\/code><\/li>\n\n\n\n<li><strong>Storage credential:<\/strong> <code>SC_catalog_storage<\/code><\/li>\n\n\n\n<li><strong>URL:<\/strong> <code>abfss:\/\/data@&lt;storage_account&gt;.dfs.core.windows.net\/ADB\/external-tables\/<\/code><\/li>\n\n\n\n<li><strong>Create<\/strong> \u2192 <strong>Test connection<\/strong> (should show all permissions OK).<\/li>\n<\/ul>\n\n\n\n<p><strong>SQL equivalent<\/strong> (does the same thing):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE EXTERNAL LOCATION `ext_tables`\nURL 'abfss:\/\/data@&lt;storage_account&gt;.dfs.core.windows.net\/ADB\/external-tables\/'\nWITH STORAGE CREDENTIAL `SC_catalog_storage`;\n<\/code><\/pre>\n\n\n\n<p>Reference: SQL syntax for <strong>CREATE EXTERNAL LOCATION<\/strong>. (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-create-location?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">03:37 \u2014 Managed Tables vs External Tables (same schema)<\/h2>\n\n\n\n<p>We\u2019ll use catalog <strong><code>Dev<\/code><\/strong> and schema <strong><code>bronze<\/code><\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Tip: attach your SQL notebook to a <strong>Unity Catalog\u2013enabled<\/strong> cluster before running.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1) Create a <strong>managed<\/strong> table and insert a row<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Managed table (no LOCATION clause)\nCREATE TABLE Dev.bronze.sales_managed (\n  id INT,\n  product STRING,\n  amount DOUBLE\n);\n\nINSERT INTO Dev.bronze.sales_managed VALUES (1, 'Laptop', 1200.50);\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2) Create an <strong>external<\/strong> table and insert a row<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>External table requires a <strong>LOCATION<\/strong> pointing into your external location path.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>-- External table (explicit LOCATION under the external location root)\nCREATE TABLE Dev.bronze.sales_external (\n  id INT,\n  product STRING,\n  amount DOUBLE\n)\nLOCATION 'abfss:\/\/data@&lt;storage_account&gt;.dfs.core.windows.net\/ADB\/external-tables\/sales_external';\n\nINSERT INTO Dev.bronze.sales_external VALUES (2, 'Phone', 750.00);\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3) Verify each table\u2019s <strong>type<\/strong> and <strong>storage path<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Managed table details\nDESCRIBE EXTENDED Dev.bronze.sales_managed;\n\n-- External table details\nDESCRIBE EXTENDED Dev.bronze.sales_external;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sales_managed<\/code> \u2192 <strong>tableType = MANAGED<\/strong>, path resolves to your <strong>metastore<\/strong> managed storage (Unity Catalog-managed).<\/li>\n\n\n\n<li><code>sales_external<\/code> \u2192 <strong>tableType = EXTERNAL<\/strong>, path is exactly the <strong>LOCATION<\/strong> you specified under <code>\/ADB\/external-tables\/<\/code>.<br>Background docs on table types. (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/tables\/?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">07:07 \u2014 UNDROP in Databricks (recover dropped tables)<\/h2>\n\n\n\n<p>Now we\u2019ll <strong>drop<\/strong> both tables and recover them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Drop the tables<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP TABLE Dev.bronze.sales_managed;\nDROP TABLE Dev.bronze.sales_external;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In <strong>Unity Catalog<\/strong>, dropping a <strong>managed<\/strong> table does <strong>not<\/strong> immediately delete data from cloud storage; it\u2019s <strong>eligible for cleanup within ~7\u201330 days<\/strong>.<\/li>\n\n\n\n<li>You can <strong>recover (UNDROP)<\/strong> a dropped relation within <strong>7 days<\/strong>. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2) List dropped tables (get names\/IDs)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>USE CATALOG Dev;\n\n-- See dropped tables for a schema\nSHOW TABLES DROPPED IN Dev.bronze;\n<\/code><\/pre>\n\n\n\n<p>You\u2019ll get rows including <code>tablename<\/code>, <code>tableid<\/code> (UUID), <code>deletedat<\/code>, and more. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-aux-show-tables-dropped?utm_source=chatgpt.com\">Microsoft Learn<\/a>)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) <strong>UNDROP<\/strong> by <strong>name<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>UNDROP TABLE Dev.bronze.sales_managed;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Parent <strong>catalog<\/strong> and <strong>schema<\/strong> must still exist.<\/li>\n\n\n\n<li>Recovers the <strong>most recently<\/strong> dropped relation with that name in the schema. (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-undrop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4) <strong>UNDROP<\/strong> by <strong>ID<\/strong> (alternative)<\/h3>\n\n\n\n<p>Copy the <code>tableid<\/code> for <code>sales_external<\/code> from <code>SHOW TABLES DROPPED<\/code>, then:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UNDROP TABLE WITH ID '&lt;table_uuid_from_show_tables_dropped&gt;';\n<\/code><\/pre>\n\n\n\n<p>The <strong><code>WITH ID<\/code><\/strong> form is handy if a new table with the same name was recreated and blocks name-based recovery (in that case you can rename the new one or use the ID). (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-undrop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>, <a href=\"https:\/\/kb.databricks.com\/en_US\/unity-catalog\/undrop-table-not-working-when-a-newer-table-and-the-dropped-table-have-the-same-name?utm_source=chatgpt.com\">kb.databricks.com<\/a>)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Keep in mind<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>UNDROP<\/strong> works for both <strong>managed<\/strong> and <strong>external<\/strong> relations in Unity Catalog.<\/li>\n\n\n\n<li><strong>Managed<\/strong>: data is soft-retained for up to the 7-day recovery window, then scheduled for deletion (within ~7\u201330 days).<\/li>\n\n\n\n<li><strong>External<\/strong>: <strong>data files always remain<\/strong> at your external path; dropping only removes UC metadata. You can still UNDROP within 7 days to re-register. (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-undrop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>, <a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Microsoft Learn<\/a>)<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">(Optional) Quick sanity checks in storage<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Managed table (after drop, before cleanup): you\u2019ll still see data under the Unity Catalog managed path (e.g., metastore-scoped \u201ctables\/<code>&lt;table-id&gt;<\/code>\/\u201d). Cleanup is deferred. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Microsoft Learn<\/a>)<\/li>\n\n\n\n<li>External table: data remains at <code>\/ADB\/external-tables\/sales_external\/<\/code> regardless; dropping only removes the table\u2019s entry from the catalog. (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/tables\/?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Clean-up (optional)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Re-drop if you restored them\nDROP TABLE IF EXISTS Dev.bronze.sales_managed;\nDROP TABLE IF EXISTS Dev.bronze.sales_external;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">References (docs used)<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>UNDROP<\/strong> command (Azure &amp; Databricks docs): retention <strong>7 days<\/strong> to recover. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-ddl-undrop-table?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-undrop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n\n\n\n<li><strong>DROP TABLE<\/strong> behavior: deletion <strong>within 7\u201330 days<\/strong> for managed tables in UC. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-drop-table?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n\n\n\n<li><strong>SHOW TABLES DROPPED<\/strong> (to list droppped relations and IDs). (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/sql\/language-manual\/sql-ref-syntax-aux-show-tables-dropped?utm_source=chatgpt.com\">Microsoft Learn<\/a>)<\/li>\n\n\n\n<li><strong>External locations<\/strong> (how to configure + SQL syntax). (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/connect\/unity-catalog\/cloud-storage\/external-locations?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/sql\/language-manual\/sql-ref-syntax-ddl-create-location?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n\n\n\n<li><strong>Table types<\/strong> overview (managed vs external). (<a href=\"https:\/\/docs.databricks.com\/aws\/en\/tables\/?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n\n\n\n<li><strong>What\u2019s New \/ August 2024 releases<\/strong> (staged rollouts). (<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/databricks\/release-notes\/product\/2024\/august?utm_source=chatgpt.com\">Microsoft Learn<\/a>, <a href=\"https:\/\/docs.databricks.com\/aws\/en\/release-notes\/product\/2024\/august?utm_source=chatgpt.com\">Databricks Documentation<\/a>)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Databricks Unity Catalog Tutorial Managed vs External Tables + UNDROP (with External Location setup) Introduction (what we\u2019ll build) You\u2019ll learn to: What\u2019s new in Databricks? (Updates &amp;&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-770","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=770"}],"version-history":[{"count":2,"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":772,"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/770\/revisions\/772"}],"wp:attachment":[{"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dataopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}