Chapter 2
Chapter 2
Terminologies
Tables=relation Relationship(association)
Degree of relation(number of entity types)
Entities
Cardinality of a relation(number of instances/tuples that can be
Attribute
associated)
Column=field Constraints(rule)
Tuple=row
Cont…
ENTITIES: The entities (persons, places, things etc.) which the organization has to deal with.
The name given to an entity should always be a singular noun descriptive of each item to
be stored in it.
ATTRIBUTES - The items of information which characterize and describe these entities.
Types of Attributes
Simple (atomic) Vs Composite attributes
Simple: These are atomic values which cannot be divided into sub parts.
E.g. Age, gender, salary etc.
RELATIONSHIPS: The relationships between entities which exist and must be taken into account when processing
information.
The number of entities and the number of tuples participating in the association. These two concepts are
• Unary/recursive relationship: Tuples/records of a Single entity are related with each other.
Continue…
• n-ary relationship: Tuples from arbitrary number of entity sets are participating in a relationship.
Continue…
Cardinality of a Relationship: is the number of instances/tuples that can be associated with a single instance from one
entity in a single relationship.
The number of instances participating or associated with a single instance from an entity in a relationship is called the
cardinality of the relationship.
The major cardinalities of a relationship are:
One-to-one: one tuple is associated with only one other tuple.
o E.g. Building -to- Location
One-to-many: one tuple can be associated with many other tuples, but not the reverse.
o E.g. Department-to-Student
• Many-to-one: many tuples are associated with one tuple but not the reverse.
o E.g. Employee–to-Department
Many-to-many: one tuple is associated with many other tuples and from the other side, with a different role name one
tuple will be associated with many tuples.
o E.g. Student–to-Course
Relational Constraints
A constraint is a rule that is used for optimization purposes.
Constraints can be categorized:
A NOT NULL constraint is a rule that prevents null values from being entered into one or more columns within a table.
The DEFAULT constraint is used to set a default value for a column. The default value will be added to all new
records, if no other value is specified.
A unique constraint (also referred to as a unique key constraint) is a rule that forbids duplicate values in one or more
columns within a table. we can save a null value, but, only one NULL value is supported.
A primary key constraint is a column or combination of columns that has the same properties as a unique constraint. In the
case of a primary key, we cannot save NULL values.
A foreign key constraint (also referred to as a referential constraint or a referential integrity constraint) is a logical rule
about values in one or more columns in one or more tables.
A table check constraint (also called a check constraint) sets restrictions on data that is added to a specific table.
Relational Integrity
Domain integrity: No value of the attribute should be beyond the allowable limits.
Entity integrity: In a base relation, no attribute of a Primary Key can assume a value of NULL.
Referential integrity: If a Foreign Key exists in a relation, either the Foreign Key value must match a
Candidate Key value in its home relation or the Foreign Key value must be NULL.
Enterprise integrity: Additional rules specified by the users or database administrators of a database are
incorporated.
Key Constraints
A key refers to an attribute/a set of attributes that help us identify a row (or tuple) uniquely in a table (or relation).
A key is also used to establish relationship between the different columns and tables of a relational database.
Types of Keys:
A super key: A super key also known as super set is then a set of one or more attributes that in group (collectively) can identify an
entity uniquely from the entity set.
Example: “EMPLOYEES” entity set (“EmpId”, “EmpId, Name”, “NationalId”, “NationalId, BDate”)
Candidate Key: an attribute or set of attributes that uniquely identifies individual occurrences of an entity type or tuple within a
relation.
A candidate key has two properties:
• Uniqueness
• Irreducibility
Alternate key: is a candidate key that are not selected as primary key are called Alternate key.
Primary key: the candidate key that is selected to identify tuples uniquely within the relation.
Foreign key: an attribute, or set of attributes, within one relation that matches the candidate key of some relation
Referential Constraint
Relational language and Views
The two categories or types of relations are Base (Named) and View (Unnamed) Relations.
Base (Named Relation): A named relation corresponding to an entity in the conceptual schema, whose tuples
View (Unnamed Relation): A View is the dynamic result of one or more relational operations operating on the
base relations to produce another virtual relation that does not actually exist as presented.
Cont…
Purpose of a view
Update on views derived from various relations is not allowed since it may violate the integrity of the
database.