# Module Documentation: eml-constraint | Back to EML Contents

### The eml-constraint module - Relationships among and within dataset entities

The eml-constraint schema defines the integrity constraints between entities (e.g., data tables) as they would be maintained in a relational management system. These constraints include primary key constraints, foreign key constraints, unique key constraints, check constraints, and not null constraints, among potential others.

## Module details

Recommended Usage: | All datasets where there are logical constraints between entities
Stand-alone: | no
Imports: | eml-documentation, eml-resource
Imported By: |
View an image of the schema: | eml-constraint image

## Element Definitions:
#### primaryKey | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
ConstraintBaseGroup |  |
key | required |
)
| The primaryKey element declares the primary key in the entity to which the defined constraint pertains. Example(s): date site
#### key | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
attributeReference | required | unbounded
)
| The key element defines the set of attributes to which this constraint applies. For a primary key or a unique key, the set of attributes must be identifying. For a foreign key, the set of attributes must match an identifying key in the referenced entity. For a 'not null' constraint, the key indicates the attribute which should not be null. Example(s): site plot
#### attributeReference | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The attributeReference element is the identifier of an attribute that can be found in the identified entity. This id will be unique within an entity and specifies that the attribute participates in the key that is being defined. Example(s): site
#### uniqueKey | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
ConstraintBaseGroup |  |
key | required |
)
| The uniqueKey element represents a unique key within the referenced entity. This is different from a primary key in that it does not form any implicit foreign key relationships to other entities, however it is required to be unique within the entity. Example(s): date
#### key | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
attributeReference | required | unbounded
)
| The key element defines the set of attributes to which this constraint applies. For a primary key or a unique key, the set of attributes must be identifying. For a foreign key, the set of attributes must match an identifying key in the referenced entity. For a 'not null' constraint, the key indicates the attribute which should not be null. Example(s): date, site, plot
#### attributeReference | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The attributeReference element is the identifier of an attribute that can be found in the identified entity. This id will be unique within an entity and specifies that the attribute participates in the key that is being defined. Example(s): site
#### checkConstraint | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
ConstraintBaseGroup |  |
checkCondition | required |
)
Attributes: | Use: | Default Value:
language | optional
| The checkConstraint element defines a constraint which checks a conditional clause within an entity. Example(s): if site>1 then plot>10
#### checkCondition | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The checkCondition element defines an SQL statement or other language implementation of the condition for a check constraint. Generally this provides a means for constraining the values within and among entities. Example(s): (year > 1900 and year < 1990)
#### foreignKey | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
| The foreignKey element defines a foreign key relationship among entities which relates this entity to another's primary key.
#### joinCondition | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
ForeignKeyGroup |  |
referencedKey | required |
)
| The joinCondition element describes any join of two tables that is not done with a primary/foreign key relationship. Example(s): JOIN code
#### referencedKey | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
attributeReference | required | unbounded
)
| The referencedKey element defines set of attributes to which a foreign key constraint refers. If the key refers to the primary key in the referenced entity, then the "referencedKey" is optional. For a foreign key, the set of attributes must match an identifying key in the referenced entity. Example(s): site, plot
#### attributeReference | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The attributeReference element is the identifier of an attribute that can be found in the identified entity. This id will be unique within an entity and specifies that the attribute participates in the key that is being defined. Example(s): site
#### notNullConstraint | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
ConstraintBaseGroup |  |
key | required |
)
| The notNullConstraint element defines a constraint that indicates that no null values should be present for an attribute in this entity.
#### key | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
attributeReference | required | unbounded
)
| The key element defines the set of attributes to which this constraint applies. For a primary key or a unique key, the set of attributes must be identifying. For a foreign key, the set of attributes must match an identifying key in the referenced entity. For a 'not null' constraint, the key indicates the attribute which should not be null.
#### attributeReference | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The attributeReference element is the identifier of an attribute that can be found in the identified entity. This id will be unique within an entity and specifies that the attribute participates in the key that is being defined. Example(s): site
#### constraintName | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The constraintName element is a name which represents a human readable and meaningful name for the constraint. Example(s): PrimaryKey_birdSurvey
#### constraintDescription | This element has no default value.
Content of this field: | Description of this field:
| The constraintDescription element describes the nature of the constraint. It might be a description of a check condition, or a statement about the composition of a primary key or the nature of the relationship between two database tables or two ascii files. Example(s): 1.Must be greater than 0 but less than 100 2. "The primary key of the table BIRD_SURVEY is composed of two attributes:speciesCode and observationDate 3. The species name associated with the species code in survey.txt can be found in the file speciesList.txt
#### key | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
attributeReference | required | unbounded
)
| The key element defines the set of attributes to which this constraint applies. For a primary key or a unique key, the set of attributes must be identifying. For a foreign key, the set of attributes must match an identifying key in the referenced entity. For a 'not null' constraint, the key indicates the attribute which should not be null.
#### attributeReference | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The attributeReference element is the identifier of an attribute that can be found in the identified entity. This id will be unique within an entity and specifies that the attribute participates in the key that is being defined. Example(s): site
#### entityReference | This element has no default value.
Content of this field: | Description of this field:
Type: res:NonEmptyStringType
| The entityReference element contains the id of the entity to which a foreign key refers, otherwise known as the parent-entity or parent-table. This should be an identifier that matches one of the "identifier" elements for an entity. Example(s): knb.79.4
#### relationshipType | This element has no default value.
Content of this field: | Description of this field:
| The relationshipType element defines identifying relationships that propagate from the parent entity's primary key to the child's primary key. Non-identifying relationships propagate the parent's primary key as a non-key attribute of the child entity. Example(s): relationshipType code
Derived from: xs:string (by xs:restriction) Allowed values: identifying non-identifying
#### cardinality | This element has no default value.
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
parentOccurences | required |
childOccurences | required |
)
| The cardinality element represents a statement of the relationship between parent and child entities. Cardinality is expressed as the ratio of related parent and child entities. Cardinality 1 to N is a specific form of cardinality in which zero or one parent records are related to a specified number of child records. The cardinality ratio for the parent entity depends on whether the "existence" is mandatory (one or more) or optional (zero to ...). Example(s): One to many One to 10 Zero or One to Many
#### parentOccurences | This element has no default value.
Content of this field: | Description of this field:
| The parentOccurences element describes the Parent portion of a 1 to exactly N cardinality. May have a value of either 0 or 1. Value of 0 implies that the "existence" of a child record is optional. Value of 1 implies that the "existence" of a child record is mandatory. Example(s): One to 10, Zero or One to Many
Derived from: xs:integer (by xs:restriction) Allowed values: 0 1
#### childOccurences | This element has no default value.
Content of this field: | Description of this field:
Type: CardinalityChildOccurancesType
| The childOccurences element describes the child portion of a cardinality expression Allowed values are positive integers including zero or the string value "many" Example(s): 2, 15, many
## Attribute Definitions:
#### language
Type: xs:string Use: optional | The language element declares the language that is used to implement the check constraint. This is typically the name and version of a programming language such as Java, C, Perl, Basic, or other. Sometime it is the name and version of a scriptable analysis system such as SAS, Matlab, R, or SPlus. Example(s): Perl 5.6.1
#### id
Type: res:IDType Use: optional
#### system
Type: res:SystemType Use: optional
#### scope
Type: res:ScopeType Use: optional Default value: document
## Complex Type Definitions:
#### ConstraintType |
Content of this field: | Description of this field:
Elements: | Use: | How many:
A choice of (
primaryKey | required |
OR
uniqueKey | required |
OR
checkConstraint | required |
OR
foreignKey | required |
OR
joinCondition | required |
OR
notNullConstraint | required |
)
Attributes: | Use: | Default Value:
id | optional
system | optional
scope | optional | document
| The ConstraintType type describes the relational integrity constraints of a relational database. This includes primary keys, foreign keys, unique keys, etc. When an eml-constraint module is created, it should be linked into a dataset using the "triple" element, and all of the entities that are referenced in the constraints should be accessible within that same package.
## Simple Type Definitions:
### #### CardinalityChildOccurancesType
| The CardinalityChildOccurancesType element defines the child portion of a cardinality expression. Allowed values are positive integers including zero or the string value "many". Example(s): 0,1, 2, 15,many
## Group Definitions:
#### ConstraintBaseGroup |
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
constraintName | required |
constraintDescription | optional |
)
#### ForeignKeyGroup |
Content of this field: | Description of this field:
Elements: | Use: | How many:
A sequence of (
ConstraintBaseGroup |  |
key | required |
entityReference | required |
relationshipType | optional |
cardinality | optional |
)

Web Contact: jones@nceas.ucsb.edu