Expand my Community achievements bar.

SOLVED

How to set a specific field as Primary Key?

Avatar

Level 5

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>

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ogonzalesdiaz ,

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"

View solution in original post

3 Replies

Avatar

Level 5

Hi @ogonzalesdiaz,

 

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

Avatar

Correct answer by
Community Advisor

Hi @ogonzalesdiaz ,

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"

Avatar

Level 5

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>