Foreign Keys in Format File

<< Click to Display Table of Contents >>

Navigation:  EDP > Customizability >

Foreign Keys in Format File

Foreign keys are used for linking one row in a section to another row in a different section. A foreign key must reference an existing primary key. For every field within a foreign key, there must be a field in the referenced primary with the same name and same data type. Below is an excerpt from an EQuIS Format Definition (EFD) file that illustrates the relationship between a primary key and a foreign key.

 

'Foreign Key

 

     <xs:keyref name="FK_FieldResult_FieldSample" refer="PK_FieldSample">

 

           <xs:selector xpath=".//FieldResult" />

 

           <xs:field xpath="sys_sample_code" />

 

     </xs:keyref>

 

 

'Primary Key

 

<xs:key name="PK_FieldSample">

 

           <xs:selector xpath=".//FieldSample" />

 

           <xs:field xpath="sys_sample_code" />

     </xs:key>

 

In the foreign key, the attribute refer is the name of the primary key it references (as shown by the name attribute in the primary key). The xpath attribute in the selector tag is used for specifying which section the foreign key is for. The xpath attribute in the field tag is the name of the field to include as part of the foreign key. If there is more than one field in the primary key or foreign key, then the number of fields in both must be the same, with the same name and the same type. If there is only one field in each, then the name of the fields do not have to match, and they may also be in the same section as shown below.

 

'Foreign Key

 

'When there is only one field in the foreign key and primary key, the field names can be different. Foreign key does not have to references a different section.

 

<xs:keyref name="FK_LabSample_v1_parent_sample" refer="PK_LabSample_v1">

 

           <xs:selector xpath=".//LabSample_v1" />

 

           <xs:field xpath="parent_sample_code" />

 

</xs:keyref>

 

 

 

'Primary Key

 

<xs:key name="PK_LabSample_v1">

 

           <xs:selector xpath=".//LabSample_v1" />

 

           <xs:field xpath="sys_sample_code" />

 

     </xs:key>