<?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 Re: How to enforce delta table column to have unique values? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/58697#M31243</link>
    <description>&lt;P&gt;I'm with you.&amp;nbsp; But it DOES make sense because DBx databases are not application databases.&amp;nbsp; DBx is not intended to be used like this.&amp;nbsp; DBx databases are repositories for any ingested abstract data.&amp;nbsp; To manage the ingestion is purpose-built databases architecture implies using an external DBMS such as AzureDB.&lt;BR /&gt;For instance, you would build a point of sale (POS) system to run on DBx.&amp;nbsp; But you would put your data analytics of the POS on DBx.&amp;nbsp;&lt;BR /&gt;All that said there isn't anything that prevents you from using a MERGE query, or writing additional query code, to guaranteeing uniqueness.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 13:40:30 GMT</pubDate>
    <dc:creator>Steve_Lyle_BPCS</dc:creator>
    <dc:date>2024-01-30T13:40:30Z</dc:date>
    <item>
      <title>How to enforce delta table column to have unique values?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/7098#M3074</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have defined a delta table with a primary key:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%sql
&amp;nbsp;
CREATE TABLE IF NOT EXISTS test_table_pk (
  table_name STRING NOT NULL,
  label STRING NOT NULL,
  table_location STRING NOT NULL,
&amp;nbsp;
  CONSTRAINT test_table_pk_col PRIMARY KEY(table_name)  
  
  ) USING DELTA
LOCATION "abfss://raw@Table_Path"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want column "table_name" to be unique. However, I can insert rows with the same "table_name" as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%sql
&amp;nbsp;
INSERT INTO test_table_pk 
VALUES ('table_2', 'label_2', 'path_2'), 
       ('table_2', 'label_2', 'path_3');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the table:&lt;/P&gt;&lt;P&gt;&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/486i4CBAA396181C7604/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to add a unique constraint for column "table_name":&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"CONSTRAINT test_table_unique_col UNIQUE(table_name)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but I get the error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Only PRIMARY KEY and FOREIGN KEY constraints are currently supported&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I add a constraint to the column "table_name" to accept only unique values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 01:28:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/7098#M3074</guid>
      <dc:creator>Mado</dc:creator>
      <dc:date>2023-03-26T01:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to enforce delta table column to have unique values?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/7099#M3075</link>
      <description>&lt;P&gt;Hi @Mohammad Saber​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;For now, there is no way to enforce delta table column to have unique values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use primary key and foreign key relationships on fields in Unity Catalog tables. Primary and foreign keys are informational only and are not enforced. Foreign keys must reference a primary key in another table.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 09:05:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/7099#M3075</guid>
      <dc:creator>Ajay-Pandey</dc:creator>
      <dc:date>2023-03-26T09:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to enforce delta table column to have unique values?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/46599#M28076</link>
      <description>&lt;P&gt;This doesn't make much sense, as the role of a primary key is to have a unique constraint. Is there something on the roadmap to have unique constraints for primary keys in the future? Also how can the current PK constraints be used in any way?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 13:52:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/46599#M28076</guid>
      <dc:creator>darthdickhead</dc:creator>
      <dc:date>2023-09-28T13:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to enforce delta table column to have unique values?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/58697#M31243</link>
      <description>&lt;P&gt;I'm with you.&amp;nbsp; But it DOES make sense because DBx databases are not application databases.&amp;nbsp; DBx is not intended to be used like this.&amp;nbsp; DBx databases are repositories for any ingested abstract data.&amp;nbsp; To manage the ingestion is purpose-built databases architecture implies using an external DBMS such as AzureDB.&lt;BR /&gt;For instance, you would build a point of sale (POS) system to run on DBx.&amp;nbsp; But you would put your data analytics of the POS on DBx.&amp;nbsp;&lt;BR /&gt;All that said there isn't anything that prevents you from using a MERGE query, or writing additional query code, to guaranteeing uniqueness.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 13:40:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/58697#M31243</guid>
      <dc:creator>Steve_Lyle_BPCS</dc:creator>
      <dc:date>2024-01-30T13:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to enforce delta table column to have unique values?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/115935#M45220</link>
      <description>&lt;P&gt;CREATE TABLE table_name (&lt;BR /&gt;id_col1 BIGINT GENERATED ALWAYS AS IDENTITY,&lt;BR /&gt;id_col2 BIGINT GENERATED ALWAYS AS IDENTITY (START WITH -1 INCREMENT BY 1),&lt;BR /&gt;id_col3 BIGINT GENERATED BY DEFAULT AS IDENTITY,&lt;BR /&gt;id_col4 BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH -1 INCREMENT BY 1)&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;This is the only way you can create an identity column in sparkSQL for delta lake table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Apr 2025 16:36:02 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-enforce-delta-table-column-to-have-unique-values/m-p/115935#M45220</guid>
      <dc:creator>SibbirSihan</dc:creator>
      <dc:date>2025-04-20T16:36:02Z</dc:date>
    </item>
  </channel>
</rss>

