2.10 Table Management and Properties
Key Takeaways
- ALTER TABLE commands modify table schema, properties, and constraints without rewriting data.
- Table properties (TBLPROPERTIES) configure Delta Lake behavior including retention duration, change data feed, and optimization settings.
- DESCRIBE TABLE EXTENDED shows complete table metadata including schema, location, properties, and table type.
- DROP TABLE removes a table — for managed tables this also deletes data; for external tables only metadata is removed.
- COMMENT ON adds documentation to tables, columns, and schemas, improving data discoverability in the Catalog Explorer.
Last updated: March 2026
Table Management and Properties
Quick Answer: Use ALTER TABLE to modify schemas and properties. TBLPROPERTIES control Delta Lake behavior. DESCRIBE TABLE EXTENDED shows full metadata. COMMENT ON adds documentation for discoverability.
ALTER TABLE Operations
Add and Modify Columns
-- Add a new column
ALTER TABLE orders ADD COLUMN shipping_cost DECIMAL(10,2);
-- Add multiple columns
ALTER TABLE orders ADD COLUMNS (
discount DECIMAL(10,2),
coupon_code STRING
);
-- Rename a column
ALTER TABLE orders RENAME COLUMN shipping_cost TO delivery_cost;
-- Change column type (must be compatible: e.g., INT to BIGINT)
ALTER TABLE orders ALTER COLUMN quantity TYPE BIGINT;
-- Add a column comment
ALTER TABLE orders ALTER COLUMN delivery_cost COMMENT 'Cost of shipping in USD';
-- Set column to NOT NULL
ALTER TABLE orders ALTER COLUMN order_id SET NOT NULL;
-- Drop a column
ALTER TABLE orders DROP COLUMN coupon_code;
Table Properties
-- Set table properties
ALTER TABLE orders SET TBLPROPERTIES (
'delta.deletedFileRetentionDuration' = '30 days',
'delta.enableChangeDataFeed' = 'true',
'delta.logRetentionDuration' = '60 days',
'delta.autoOptimize.optimizeWrite' = 'true',
'delta.autoOptimize.autoCompact' = 'true'
);
-- Remove a property
ALTER TABLE orders UNSET TBLPROPERTIES ('delta.autoOptimize.autoCompact');
Common Table Properties
| Property | Default | Description |
|---|---|---|
| delta.deletedFileRetentionDuration | 7 days | How long VACUUM keeps old files |
| delta.logRetentionDuration | 30 days | How long transaction log history is kept |
| delta.enableChangeDataFeed | false | Enable Change Data Feed for row-level changes |
| delta.autoOptimize.optimizeWrite | false | Automatically optimize file sizes on write |
| delta.autoOptimize.autoCompact | false | Automatically compact small files |
| delta.columnMapping.mode | none | Enable column rename/drop (set to 'name') |
DESCRIBE TABLE
-- Basic schema information
DESCRIBE TABLE orders;
-- Extended metadata (location, properties, type, etc.)
DESCRIBE TABLE EXTENDED orders;
-- Column-level detail
DESCRIBE TABLE orders order_id;
-- Show table creation DDL
SHOW CREATE TABLE orders;
Table Documentation
-- Add table comment
COMMENT ON TABLE orders IS 'Production order data from the e-commerce platform. Updated daily via the ETL pipeline.';
-- Add column comments
ALTER TABLE orders ALTER COLUMN total_amount COMMENT 'Total order amount in USD including tax and shipping';
ALTER TABLE orders ALTER COLUMN order_status COMMENT 'Current status: pending, confirmed, shipped, delivered, cancelled';
-- Schema-level comment
COMMENT ON SCHEMA sales IS 'Sales department tables including orders, customers, and products';
DROP and UNDROP
-- Drop a managed table (deletes data AND metadata)
DROP TABLE orders;
-- Drop an external table (deletes metadata only)
DROP TABLE external_orders;
-- Drop only if exists (no error if table missing)
DROP TABLE IF EXISTS temp_staging;
-- Undrop a managed table within retention period (Unity Catalog)
UNDROP TABLE orders;
On the Exam: Know the difference between managed table DROP (deletes data) and external table DROP (keeps data). Understand key TBLPROPERTIES like deletedFileRetentionDuration and enableChangeDataFeed.
Test Your Knowledge
A data engineer needs to enable Change Data Feed on an existing Delta table. Which command should they use?
A
B
C
D
Test Your Knowledge
What does DESCRIBE TABLE EXTENDED show that DESCRIBE TABLE does not?
A
B
C
D
Test Your Knowledge
Which table property controls how long VACUUM retains old data files before deleting them?
A
B
C
D