Key management management-of-keys

Each table associated with a data schema must have at least one key for identifying a record in a table.

A key is declared from the main element of the data schema.

<key name="name_of_key">
  <keyfield xpath="xpath_of_field1"/>
  <keyfield xpath="xpath_of_field2"/>
  ...
</key>

A key is known as a ‘primary key’ when it is the first in the schema to be populated, or if it contains the internal attribute set to “true”.

A key can reference one or more fields in the table.

Example:

  • Adding a key to the e-mail address and city:

    code language-sql
    <srcSchema name="recipient" namespace="cus">
      <element name="recipient">
        <key name="email">
          <keyfield xpath="@email"/>
          <keyfield xpath="location/@city"/>
        </key>
    
        <attribute name="email" type="string" length="80" label="Email" desc="E-mail address of recipient"/>
        <element name="location" label="Location">
          <attribute name="city" type="string" length="50" label="City" userEnum="city"/>
        </element>
      </element>
    </srcSchema>
    

    The schema generated:

    code language-sql
    <schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
      <element name="recipient" sqltable="CusRecipient">
       <key name="email">
        <keyfield xpath="@email"/>
        <keyfield xpath="location/@city"/>
       </key>
    
       <attribute desc="E-mail address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
       <element label="Location" name="location">
         <attribute label="City" length="50" name="city" sqlname="sCity" type="string" userEnum="city"/>
       </element>
      </element>
    </schema>
    
  • Adding a primary or internal key on the “id” name field:

    code language-sql
    <srcSchema name="recipient" namespace="cus">
      <element name="recipient">
        <key name="id" internal="true">
          <keyfield xpath="@id"/>
        </key>
    
        <key name="email">
          <keyfield xpath="@email"/>
        </key>
    
        <attribute name="id" type="long" label="Identifier"/>
        <attribute name="email" type="string" length="80" label="Email" desc="E-mail address of recipient"/>
      </element>
    </srcSchema>
    

    The schema generated:

    code language-sql
    <schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
      <element name="recipient" sqltable="CusRecipient">
        <key name="email">
          <keyfield xpath="@email"/>
        </key>
    
        <key internal="true" name="id">
         <keyfield xpath="@id"/>
        </key>
    
        <attribute label="Identifier" name="id" sqlname="iRecipientId" type="long"/>
        <attribute desc="E-mail address of recipient" label="Email" length="80" name="email" sqlname="sEmail" type="string"/>
      </element>
    </schema>
    

Primary key - Identifier primary-key

In the context of an Enterprise (FFDA) deployment, the primary key of Adobe Campaign tables is a Universally Unique ID (UUID) auto-generated by the database engine. The key value is unique in the entire database. The content of the key is automatically generated on insertion of the record.

Example

In the example below, we declare an incremental key in the source schema:

<srcSchema name="recipient" namespace="cus">
  <element name="recipient"  autopk="true" autouuid="true">
  ...
  </element>
</srcSchema>

The schema generated:

<schema mappingType="sql" name="recipient" namespace="cus" xtkschema="xtk:schema">
  <element name="recipient"  autopk="true" autouuid="true" sqltable="CusRecipient">

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

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

In addition to the definition of the key, a numeric field called “id” has been added to the extended schema in order to contain the auto-generated primary key.

CAUTION
A record with a primary key set to 0 is automatically inserted on creation of the table. This record is used to avoid outer joins, which are not effective on volume tables. By default, all foreign keys are initialized with value 0 so that a result can always be returned on the join when the data item is not populated.
recommendation-more-help
35662671-8e3d-4f04-a092-029a056c566b