How to set a specific field as Primary Key? | Community
Skip to main content
Level 6
September 6, 2024
Solved

How to set a specific field as Primary Key?

  • September 6, 2024
  • 2 replies
  • 806 views

Here my current schema, but I'd like to make the attribute the primary key:

<attribute label="aaa" name="aaa" type="string"/>

How to do so?

<srcSchema _cs="DTI_XXX (abc)" created="2024-08-26 19:36:36.581Z" createdBy-id="0"
entitySchema="xtk:srcSchema" img="xtk:schema.png" label="DTI_XXX"

lastModified="2024-09-06 03:50:16.385Z" mappingType="sql" md5="AF12309BC7EC4DD0D7B62A928E490687"
modifiedBy-id="0" name="DTI_XXX" namespace="abc" xtkschema="xtk:srcSchema">
<createdBy _cs="c (cccc)"/>
<modifiedBy _cs="c (cccc)"/>


<element autopk="true" label="DTI_XXX" name="DTI_XXX">

<attribute label="aaa" name="aaa" type="string"/>
</element>
</srcSchema>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ParthaSarathy

Hi @god_prophet ,

To create custom primary key, use the below syntax,

<element label="DTI_XXX" name="DTI_XXX"> <key internal="true" name="customPrimaryKey"> <keyfield xpath="@aaa"/> </key> <attribute label="aaa" name="aaa" type="string"/> </element>

You can remove autopk="true"

2 replies

ccg1706
Community Advisor
Community Advisor
September 6, 2024

Hi @god_prophet,

 

You can make the attribute aaa the primary key  by adding primarykey="true". Additionally, you will need to modify the autopk="false", so that it does not automatically generate a primary key.

 

This will be the following:

 

<element autopk="false" label="DTI_XXX" name="DTI_XXX">

<attribute label="aaa" name="aaa" type="string" primaryKey= "true"/>
</element>

 

Regards,

Celia

ParthaSarathy
Community Advisor
ParthaSarathyCommunity AdvisorAccepted solution
Community Advisor
September 6, 2024

Hi @god_prophet ,

To create custom primary key, use the below syntax,

<element label="DTI_XXX" name="DTI_XXX"> <key internal="true" name="customPrimaryKey"> <keyfield xpath="@aaa"/> </key> <attribute label="aaa" name="aaa" type="string"/> </element>

You can remove autopk="true"

~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups
Level 6
September 9, 2024

I think this is the best approache, since it lets you define a combined primary key like this:

<element label="DTI_XXX" name="DTI_XXX">
 
    <key internal="true" name="customPrimaryKey">
      <keyfield xpath="@aaa"/>
       <keyfield xpath="@bbb"/>
       <keyfield xpath="@ccc"/>
    </key>
 
    <attribute label="aaa" name="aaa" type="string"/>
 
</element>