Modeling Constraints Extracting constraints is what modeling is

  • Slides: 7
Download presentation
Modeling Constraints Extracting constraints is what modeling is all about. But how do we

Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely identifies a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Domain constraints: peoples’ ages are between 0 and 150. Why are these constraints useful in the implementation?

Keys A set of attributes that uniquely identify an object or entity: Person: social

Keys A set of attributes that uniquely identify an object or entity: Person: social security number name + address + age Perfect keys are often hard to find, but organizations usually invent something anyway. An object may have multiple keys: employee number, social-security number

Keys in ODL Interface Person (key ssn) { properties… } Defining multiple keys: (key

Keys in ODL Interface Person (key ssn) { properties… } Defining multiple keys: (key ssn employe. ID (name address age))

Keys in E/R Diagrams name category price No formal way to specify multiple keys

Keys in E/R Diagrams name category price No formal way to specify multiple keys in E/R diagrams Product Person address name ssn

Single Value Constraints An entity (or object) may have at most one value for

Single Value Constraints An entity (or object) may have at most one value for a given attribute or relationship. Person: name, social-security number Company: stock price How do we do this in ODL? In E/R, every attribute has at most one value. Arrows tell us about multiplicity of relations. If we have a single-valued constraint, we can either: 1. Require that the value exist (see referential integrity shortly) 2. Allow null values.

Referential Integrity Constraints A relationship has one value and the value must exist. Example:

Referential Integrity Constraints A relationship has one value and the value must exist. Example: Product made. By Company: company must exist. How do we enforce referential integrity constraints? (otherwise, we get dangling pointers) - forbid to delete a reference object, or - delete the objects that reference an object we’re deleting. In E/R diagrams: Product makes Company

Weak Entity Sets Entity sets are weak when their key attributes come from other

Weak Entity Sets Entity sets are weak when their key attributes come from other classes to which they are related. This happens if: - part-of hierarchies - splitting n-ary relations to binary. affiliation Team sport number University name