Professional Documents
Culture Documents
CHAPTER 1.3
(Mapping constraints)
Mapping Constraints
● A mapping constraint is a data constraint that expresses the number of entities to
which another entity can be related via a relationship set.
● It is most useful in describing the relationship sets that involve more than two entity
sets.
● For binary relationship set R on an entity set A and B, there are four possible mapping
cardinalities. These are as follows:
1. One to one (1:1)
2. One to many (1:M)
3. Many to one (M:1)
4. Many to many (M:M)
One-to-one
● When a single instance of an entity is associated with a single instance of another
entity, then it is called as one to one cardinality
● Here each entity of the entity set participate only once in the relationship
Example for one to one cardinality
Assume that the only male can be married to only one female and one female can be
married to only one male, this can be viewed as one to one cardinality
In one-to-one mapping, an entity in E1 is associated with at most one entity in E2, and an
entity in E2 is associated with at most one entity in E1.
One-to-many
● When is a single instance of an entity is associated with more than one instance of
another entity then this type of relationship is called one to many relationships
●Here entities in one entity set can take participation in any number of times in
relationships set and entities in another entity set can take participation only once in a
relationship set
Example for one to many cardinalities
For example in the Real world, many students can study in a single college but the student
cannot apply to more than one college at the same time
In one-to-many mapping, an entity in E1 is associated with any number of entities in E2, and
an entity in E2 is associated with at most one entity in E1.
Many-to-one
When entities in one entity set can participate only once in a relationship set and entities in
another entity can participate more than once in the relationship set, then such type of
cardinality is called many-to-one
In one-to-many mapping, an entity in E1 is associated with at most one entity in E2, and an
entity in E2 is associated with any number of entities in E1.
Many-to-many
● Here more than one instance of an entity is associated with more than one instance of
another entity then it is called many to many relationships
● In this cardinality, entities in all entity sets can take participate any number of
times in the relationship cardinality is many to many.
Example for many to many cardinality
In the Real world assume that a student can take more than one course and the single
course can be taken by any number of students this relationship will be many to many
relationship
Example:
first_name varchar(20),
last_name varchar(20)
);
customer_id int,
order_details varchar(50),
references dbo.Customer
);
Assuming, that a customer orders more than once, the above relation represents one to
many relation. Similarly we can achieve other mapping constraints based on the
requirements.
On modeling the design of the relational database we can put some restrictions like what
values are allowed to be inserted in the relation, what kind of modifications and deletions are
allowed in the relation. These are the restrictions we impose on the relational database.
1. Domain constraints
2. Key constraints
3. Entity Integrity constraints
4. Referential integrity constraints
Example:
Explanation:
In the above relation, Name is a composite attribute and Phone is a multi-values attribute, so
it is violating domain constraint.
1. These are called uniqueness constraints since it ensures that every tuple in the relation
should be unique.
2. A relation can have multiple keys or candidate keys(minimal superkey), out of which
we choose one of the keys as primary key, we don’t have any restriction on choosing
the primary key out of candidate keys, but it is suggested to go with the candidate key
with less number of attributes.
3. Null values are not allowed in the primary key, hence Not Null constraint is also a
part of key constraint.
Example:
Explanation:
In the above table, EID is the primary key, and first and the last tuple has the same value in
EID ie 01, so it is violating the key constraint.
1. Entity Integrity constraints says that no primary key can take NULL value, since
using primary key we identify each tuple uniquely in a relation.
Example:
Explanation:
In the above relation, EID is made primary key, and the primary key cant take NULL values
but in the third tuple, the primary key is null, so it is a violating Entity Integrity constraints.
1. The Referential integrity constraints is specified between two relations or tables and
used to maintain the consistency among the tuples in two relations.
2. This constraint is enforced through foreign key, when an attribute in the foreign key
of relation R1 have the same domain(s) as the primary key of relation R2, then the
foreign key of R1 is said to reference or refer to the primary key of relation R2.
3. The values of the foreign key in a tuple of relation R1 can either take the values of the
primary key for some tuple in relation R2, or can take NULL values, but can’t be
empty.
Example:
Explanation:
In the above, DNO of the first relation is the foreign key, and DNO in the second relation is
the primary key. DNO = 22 in the foreign key of the first table is not allowed since DNO =
22
is not defined in the primary key of the second relation. Therefore Referential integrity
constraints is violated here
OTHER REFRENCES