why we neeed to define autopk=true in data schema in ACC | Community
Skip to main content
Level 3
January 23, 2024
Solved

why we neeed to define autopk=true in data schema in ACC

  • January 23, 2024
  • 2 replies
  • 894 views

HI ALL

why we need to define autopk=true in data schema in ACC

 

WHAT WILL HAppEN IF WE DONT define AUTOPK=true in  data schema 

if we seT BELOW CODE IT WILL DECLARE PRIAMRY KEY

THEN AUTOPK=true in  data schema will it also declare primary key?just confused with the difference in these two

@AkshayAnand 

@Craig_Thonis 

@Manoj_Kumar_ 

@Amine_Abedour 

@Marcel_Szimonisz

@DavidKangni 

@Amit_Kumar 

@ShashankNigam02

@Ganesh5067

@Jonathon_wodnicki

 

key name="PrimaryKey" internal="true">
  <keyfield xpath="@name"/>
</key>

 

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

@jefrii ,

Schema requires an unique attribute for each data row (records), which is primary key.

If you feel you don't have a dedicated attribute as a primary key in your schema, and to insert a record define autopk="true" . This will create a attribute "id" and auto-sequence for it. So whenever a new record gets inserted, the Primary key (@id) will keeps on incrementing which will be unique.

If your schema have dedicated attribute as primary key, you don't have to use autopk and can use the primary key definition syntax as you mentioned in question part.

<key name="PrimaryKey" internal="true">
  <keyfield xpath="@name"/>
</key>

 In this case, if you try to insert 2 records with same "name" it will throw an error stating 'duplicate in primary key'

2 replies

ParthaSarathy
Community Advisor
ParthaSarathyCommunity AdvisorAccepted solution
Community Advisor
January 23, 2024

@jefrii ,

Schema requires an unique attribute for each data row (records), which is primary key.

If you feel you don't have a dedicated attribute as a primary key in your schema, and to insert a record define autopk="true" . This will create a attribute "id" and auto-sequence for it. So whenever a new record gets inserted, the Primary key (@id) will keeps on incrementing which will be unique.

If your schema have dedicated attribute as primary key, you don't have to use autopk and can use the primary key definition syntax as you mentioned in question part.

<key name="PrimaryKey" internal="true">
  <keyfield xpath="@name"/>
</key>

 In this case, if you try to insert 2 records with same "name" it will throw an error stating 'duplicate in primary key'

~  ParthaSarathy S~  Click here to join ADOBE CAMPAIGN USER GROUP for Quarterly In-person | Hybrid | Virtual Meetups
LakshmiPravallika
Community Advisor
Community Advisor
January 23, 2024

Hi @jefrii ,

 

The attribute autopk="true" is defined in the element tag of the Schema only if we require the auto incremental Primary Key sequence like 1,2,3 and so on..

 

Example : We can consider nms:recipient OOTB schema, which has autopk="true" in the schema tag, the below column and the Primary key syntax comes up in the Preview Tab even though it was not added manually in the Edit Tab of the Schema. Below is the Sample Code which gets automatically added in the Preview Tab if autopk is defined,

 

 

<attribute desc="Internal primary key" label="Primary key" name="id" sqlname="iRecipientId"
type="long"/>

<key internal="true" name="id">
<keyfield xpath="@id"/>
</key>

 

It is mandatory to define the Primary Key for any Schema in Adobe Campaign but It is not mandatory to define autopk="true" in the Schema(autopk is used as per our requirements only), If the Uniqueness is based on an attribute or combination of attributes then the Primary key should be defined on them.

 

Example: In Schema called cus:product , the 2 columns product_id and product_name are having uniqueness, then we need to define the Primary Key in edit Tab of our Schema as below:

 

<key internal="true" name="PK_product">
<keyfield xpath="@product_id"/>

<keyfield xpath="@product_name"/>
</key>

 

PFA Documentation Links for reference

 

https://experienceleague.adobe.com/docs/campaign-classic/using/configuring-campaign-classic/schema-reference/elements-attributes/element.html?lang=en

 

Regards,

Pravallika.