POST_START
<h1>Modifying Table Structure and Properties with ALTER TABLE</h1>
<p>I started my day by reviewing the latest requirements for the sales team. They needed to track customer phone numbers for better outreach and support. The existing customer table in the training.sales schema didn't have a phone column, so I decided to modify the table structure to include it.</p>
<p>I opened the Databricks notebook and connected to the Unity Catalog. I first checked the current structure of the customers table to understand what fields were already present. I ran the <code>DESCRIBE TABLE EXTENDED training.sales.customers;</code> command to get detailed metadata about the table. This helped me confirm the existing columns and properties, ensuring I wouldn't accidentally duplicate or miss any existing fields.</p>
<p>I noticed that the table didn't have a phone column, which was exactly what I needed. I decided to add it using the <code>ALTER TABLE</code> command. I wrote the SQL query: <pre><code>ALTER TABLE training.sales.customers ADD COLUMNS (phone STRING);</code></pre> and executed it. The system responded quickly, indicating the column was successfully added.</p>
<p>After adding the phone column, I wanted to verify that the change was applied correctly. I ran the <code>DESCRIBE TABLE EXTENDED training.sales.customers;</code> command again to see the updated structure. This time, the output included the new phone column, confirming that the alteration was successful.</p>
<p>Next, I was asked to rename the customer_name column to full_name for consistency with other data sources. I used the <code>ALTER TABLE training.sales.customers RENAME COLUMN customer_name TO full_name;</code> command. The operation completed without errors, and I checked the table structure once more to ensure the rename was applied.</p>
<p>Finally, I needed to set a department property for the table to indicate it belongs to the sales team. I used the <code>ALTER TABLE training.sales.customers SET TBLPROPERTIES ('department' = 'sales');</code> command. This added a new property to the table metadata, which I could later use for access control or data lineage purposes.</p>
<p>I verified the table properties by running the <code>DESCRIBE TABLE EXTENDED training.sales.customers;</code> command once more. The output now included the department property, confirming that the table metadata was updated as expected.</p>
<p>Throughout the process, I learned how to use the ALTER TABLE command to modify table structures and properties in Unity Catalog. These operations are essential for maintaining and evolving data assets in a secure and organized way. By following the steps in the curriculum, I ensured that each change was made with precision and that I could always verify the results.</p>


Leave a Reply