Good business rules
Database Analysis
The E-R Model:
Entity
Sample E-R Diagram
Examples of business rules captured by the above ER model.
Attributes
Simple versus composite attributes
A composite attribute is an attribute, such as Address, that has meaningful component parts, which are more detailed attributes.
A simple (or atomic) attribute is an attribute that cannot be broken down into smaller components that are meaningful for the organization. For example, all the attributes associated with AUTOMOBILE are simple: Vehicle ID, Color, Weight, and Horsepower.
Multivalued attribute: An attribute that may take on more than one value for a given entity (or relationship) instance.
Stored Versus Derived Attributes
Some attribute values that are of interest to users can be calculated or derived from other related attribute values that are stored in the database. For example, suppose that for an organization, the EMPLOYEE entity type has a Date Employed attribute. If users need to know how many years a person has been employed, that value can be calculated using Date Employed and today’s date.
A derived attribute is an attribute whose values can be calculated from related attribute values (plus possibly data not in the database, such as today’s date, the current time, or a security code provided by a system user).
Identifier Attribute
An identifier is an attribute (or combination of attributes) whose value distinguishes individual instances of an entity type. That is, no two instances of the entity type may have the same value for the identifier attribute.
A composite identifier is an identifier that consists of a composite attribute.
In Class Exercise 2.3
In Class Exercise 2.4
• The entity type STUDENT has the following attributes: Id (unique), Name, Phone, Age, Activity, and No_of_Year
– Activity: represents a campus-based co-curriculum activity (CCA)
– No_of_Year: the number of years the student may have engaged in this CCA
• An assumption: a given student may engage in more than one activity
• Create a single entity model for this scenario
Relationship
a relationship is an association representing an interaction among the instances of one or more entity types that is of interest to the organization. Thus, a relationship has a verb phrase name. Relationships and their characteristics (degree and cardinality) represent business rules, and usually relationships represent the most complex business rules shown in an ERD. In other words, this is where data modeling gets really interesting and fun, as well as crucial for controlling the integrity of a database.
Relationship instance
An association between (or among) entity instances where each relationship instance associates exactly one entity instance from each participating entity type.
Associative Entity
An associative entity is an entity type that associates the instances of one or more entity types and contains attributes that are peculiar to the relationship between those entity instances.
• A unary or binary relationship could be modelled as associative entity only if it is many-to-many AND it has at least one attribute
• Important notes about associative entity:
• Associative entity symbol: –Rounded angle rectangle
(a) Each employee has a common Complete_Date and a common Grade for all the courses he/she completes
(b) All the employees completing a course share the same Grade and same Complete_Date
(c) Each employee can complete different courses at different Complete_Date with different Grade. Each course can be taken by different employees at different Complete_Date with different Grade
Associative entity involves a rounded angle rectangle.
Note that the many-to-many cardinality symbols face toward the associative entity and not toward the other entities
Degree of a relationship
The degree of a relationship is the number of entity types that participate in that relationship.
Unary Relationship
A unary relationship is a relationship between the instances of a single entity type.
Binary Relationship
Ternary Relationship
A ternary relationship is a simultaneous relationship among the instances of three entity types.
Cardinality of relationship
Cardinality Constraints
- the number of instances of one entity that can or must be associated with each instance of another entity
How to Read Cardinality
Strong vs. Weak Entities, and Identifying Relationships
Strong entities
Weak entity
Identifying relationship
An instance of weak entity is identified by
- The identifier from the owner entity
- The partial identifier from itself (represented by the double-line)
An example: a dependent is identified by the Employee_ID of its owner entity EMPLOYEE and the partial identifier Dependent_Name.
Associative Entities
• It seems like a relationship: it links entities together
• Yet it seems like an entity: it has attributes
• When should a relationship with attributes instead be an associative entity?
- All relationships for the associative entity should be many
- The associative entity could have meaning independent of the other entities
- The associative entity preferably has a unique identifier (but not necessarily), and should also have other attributes
- Ternary relationships should be converted to associative entities
- (The associative entity may participate in other relationships other than the entities of the associated relationship)