<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Add Identity Column to Existing Table in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17172#M11214</link>
    <description>&lt;P&gt;Hello everyone. I am working with tables that need an identity column. I currently have a view in which I cast the different columns to the data type that I want. Now I want the result of this view to be inserted or merged into a table. The schema of the view can be reused, but an identity column (Start at 1, increment by 1) should be added. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the only option that I see, is that I define the schema of the target table somewhere (and thus write it down). I don't want this, as I would need to manage the schema in two locations (in the view where I do the casts, and the schema of the target table, although the latter script should only be executed once). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a possibility to take the schema of the view, add the identity column and use this as the schema for a new table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already tried to create a table from the view (which worked), but if I then altered the table and added the identity column, I got an error. It seems that the identity column can only be added during the creation of a table.&lt;/P&gt;&lt;P&gt;I got the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1780i56F1A4B7ADC0A9A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jun 2022 13:54:15 GMT</pubDate>
    <dc:creator>jasperputs</dc:creator>
    <dc:date>2022-06-20T13:54:15Z</dc:date>
    <item>
      <title>Add Identity Column to Existing Table</title>
      <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17172#M11214</link>
      <description>&lt;P&gt;Hello everyone. I am working with tables that need an identity column. I currently have a view in which I cast the different columns to the data type that I want. Now I want the result of this view to be inserted or merged into a table. The schema of the view can be reused, but an identity column (Start at 1, increment by 1) should be added. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the only option that I see, is that I define the schema of the target table somewhere (and thus write it down). I don't want this, as I would need to manage the schema in two locations (in the view where I do the casts, and the schema of the target table, although the latter script should only be executed once). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a possibility to take the schema of the view, add the identity column and use this as the schema for a new table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already tried to create a table from the view (which worked), but if I then altered the table and added the identity column, I got an error. It seems that the identity column can only be added during the creation of a table.&lt;/P&gt;&lt;P&gt;I got the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1780i56F1A4B7ADC0A9A5/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 13:54:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17172#M11214</guid>
      <dc:creator>jasperputs</dc:creator>
      <dc:date>2022-06-20T13:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add Identity Column to Existing Table</title>
      <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17173#M11215</link>
      <description>&lt;P&gt;At the moment that is not supported.&lt;/P&gt;&lt;P&gt;The alter table command only allows for sync identity.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 08:51:18 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17173#M11215</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2022-06-21T08:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add Identity Column to Existing Table</title>
      <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17175#M11217</link>
      <description>&lt;P&gt;Hello @Kaniz Fatma​, the answer from @Werner Stinckens​&amp;nbsp;helped. I just created a script that is used to create the table. In the script I specify the identity column and this works. &lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 08:23:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17175#M11217</guid>
      <dc:creator>jasperputs</dc:creator>
      <dc:date>2022-06-28T08:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Add Identity Column to Existing Table</title>
      <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17177#M11219</link>
      <description>&lt;P&gt;Hello @Jasper Puts​&amp;nbsp;how  did you solve this issue of creating a identity column to existing table.&lt;/P&gt;&lt;P&gt;I'm also getting the same  error as you got.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 07:10:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17177#M11219</guid>
      <dc:creator>ramankr48</dc:creator>
      <dc:date>2022-09-13T07:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add Identity Column to Existing Table</title>
      <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17178#M11220</link>
      <description>&lt;P&gt;the recent syntax is :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ALTER TABLE retaildb.sales_order ADD COLUMN sales_key3 BIGINT GENERATED ALWAYS AS IDENTITY(1,1);&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 07:11:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/17178#M11220</guid>
      <dc:creator>ramankr48</dc:creator>
      <dc:date>2022-09-13T07:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Add Identity Column to Existing Table</title>
      <link>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/106907#M42633</link>
      <description>&lt;P&gt;The above query is not working with databricks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jan 2025 13:06:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/add-identity-column-to-existing-table/m-p/106907#M42633</guid>
      <dc:creator>Vittal2</dc:creator>
      <dc:date>2025-01-24T13:06:02Z</dc:date>
    </item>
  </channel>
</rss>

