Example of an UpdateMetadata Request That Merges Associations

The following UpdateMetadata examples illustrate the use of the MERGE directive. MERGE is the default directive for multiple associations when the Function attribute is omitted from an UpdateMetadata request. MERGE adds and modifies associations without overwriting existing associations.
The first example adds UniqueKeys and ForeignKeys associations to the table objects created in Adding Metadata Objects. The UpdateMetadata request consists of two main parts:
  • It adds a UniqueKeys association to PhysicalTable A53TPPVI.A4000002 and identifies the table's Name column (A53TPPVI.A5000005) as the key column.
  • It associates the UniqueKey object with PhysicalTable A53TPPVI.A4000001 by creating a ForeignKeys association. The ForeignKey object identifies the table's Employees column (A53TPPVI.A5000004) as its key column.
<UpdateMetadata>
   <Metadata>
      <PhysicalTable Id="A53TPPVI.A4000002">
         <UniqueKeys Function="Merge">
            <UniqueKey Id="" Name="Sales Associates in
NW Region">
              <KeyedColumns Function="Merge">
                <Column ObjRef="A53TPPVI.A5000005"/>
              </KeyedColumns>
              <ForeignKeys Function="Merge">
                <ForeignKey Id="" Name="Link to Sales
Associates table">
                  <Table>
                    <PhysicalTable ObjRef="A53TPPVI.A4000001" 
                             Name="Sales offices in NW Region"/>
                  </Table>
                  <KeyedColumns Function="Merge">
                    <Column
ObjRef="A53TPPVI.A5000004"/>
                  </KeyedColumns>
                </ForeignKey>
             </ForeignKeys>
           </UniqueKey>
        </UniqueKeys> 
      </PhysicalTable>
   </Metadata>
   <NS>SAS</NS>
   <!-- OMI_TRUSTED_CLIENT Flag -->
   <Flags>268435456</Flags>  
   <Options/>
</UpdateMetadata>
In the request, note the following:
  • The Id attribute in the main element specifies a real value.
  • The Function directives in the <UNIQUEKEYS>, <KEYEDCOLUMNS>, and <FOREIGNKEYS> association elements specify to merge the new associations with any existing associations defined in the association lists of the specified tables and columns. MERGE is the default directive for multiple associations, so the directives could have been omitted from the request, and MERGE would be used.
  • The null Id values in the <UNIQUEKEY> and <FOREIGNKEY> subelements instruct the SAS Metadata Server to create new associated objects.
  • The ObjRef attribute in the <COLUMN> element specifies to create an association to an existing object.
  • The Table association is a single association. The default directive for single associations is MODIFY, which modifies an existing association or adds it if the association does not exist. Use of the ObjRef attribute prevents the table's other attributes from being modified.
Here is an example of the output returned by the SAS Metadata Server:
<!-- Using the UPDATEMETADATA method. -->

<PhysicalTable Id="A53TPPVI.A4000002">
<UniqueKeys>
<UniqueKey Id="A53TPPVI.A8000001" Name="Sales
Associates in NW Region">
<KeyedColumns>
<Column ObjRef="A53TPPVI.A5000005"/>
</KeyedColumns>
<ForeignKeys>
<ForeignKey Id="A53TPPVI.A9000001" Name="Link to Sales
Associates table">
<Table>
<PhysicalTable ObjRef="A53TPPVI.A4000001"/>
</Table>
<KeyedColumns>
<Column ObjRef="A53TPPVI.A5000004"/>
</KeyedColumns>
<PartnerUniqueKey>
<UniqueKey ObjRef="A53TPPVI.A8000001"/>
</PartnerUniqueKey>
</ForeignKey>
</ForeignKeys>
<Table>
<PhysicalTable ObjRef="A53TPPVI.A4000002"/>
</Table>
</UniqueKey>
</UniqueKeys>
</PhysicalTable>
The request created seven associations and two new objects (UniqueKey and ForeignKey).
The following example updates the UniqueKey object created in the previous request. It modifies the Name attribute of the key column and adds an association to a second key column.
<UpdateMetadata>
   <Metadata>
      <UniqueKey Id="A53TPPVI.A8000001">
         <KeyedColumns>
             <Column Id="A53TPPVI.A5000005"
Name="EmployeeName"/>
             <Column ObjRef="A53TPPVI.A5000006"/>
          </KeyedColumns>
      </UniqueKey>
   </Metadata>
   <NS>SAS</NS>
   <!-- OMI_TRUSTED_CLIENT Flag -->
   <Flags>268435456</Flags>  
   <Options/>
</UpdateMetadata>
In the request, note the following:
  • A Function directive is omitted from the request because KeyedColumns is a multiple association and the default value of MERGE is appropriate for the operation.
  • Use of the Id attribute to identify the original keyed column allows the column's properties to be updated.
  • Use of the ObjRef attribute to identify the newly associated column creates the association and does not modify any of the column's other attributes.
Here are the results of a GetMetadata request that lists the UniqueKey object's KeyedColumns associations:
<!-- Using the GETMETADATA method. -->

<UniqueKey Id="A53TPPVI.A8000001" Name="Sales Associates in NW Region">
<KeyedColumns>
<Column Id="A53TPPVI.A5000005" Name="EmployeeName"
Desc="Name of employee"/>
<Column Id="A53TPPVI.A5000006" Name="Address" Desc="Home Address"/>
</KeyedColumns>
</UniqueKey>
Two Column objects are returned. Column A53TPPVI.A5000005's Name attribute was changed from Name to EmployeeName.