Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE) PDF Download

Introduction of ER Model

ER Model is used to model the logical view of the system from data perspective which consists of these components:

1. Entity, Entity Type, Entity Set
An Entity may be an object with a physical existence – a particular person, car, house, or employee – or it may be an object with a conceptual existence – a company, a job, or a university course.
An Entity is an object of Entity Type and set of all entities is called as entity set. e.g.; E1 is an entity having Entity Type Student and set of all students is called Entity Set. In ER diagram, Entity Type is represented as:

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

2. Attribute(s)
Attributes are the properties which define the entity type. For example, Roll_No, Name, DOB, Age, Address, Mobile_No are the attributes which defines entity type Student. In ER diagram, attribute is represented by an oval.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

(i) Key Attribute: The attribute which uniquely identifies each entity in the entity set is called key attribute. For example, Roll_No will be unique for each student. In ER diagram, key attribute is represented by an oval with underlying lines.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

(ii) Composite Attribute: An attribute composed of many other attribute is called as composite attribute. For example, Address attribute of student Entity type consists of Street, City, State, and Country. In ER diagram, composite attribute is represented by an oval comprising of ovals.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

(iii) Multivalued Attribute: An attribute consisting more than one value for a given entity. For example, Phone_No (can be more than one for a given student). In ER diagram, multivalued attribute is represented by double oval.
Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

(iv) Derived Attribute: An attribute which can be derived from other attributes of the entity type is known as derived attribute. Example: Age (can be derived from DOB). In ER diagram, derived attribute is represented by dashed oval.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

The complete entity type Student with its attributes can be represented as:

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Relationship Type and Relationship Set

A relationship type represents the association between entity types. For example, ‘Enrolled in’ is a relationship type that exists between entity type Student and Course. In ER diagram, relationship type is represented by a diamond and connecting the entities with lines.


Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

A set of relationships of same type is known as relationship set. The following relationship set depicts S1 is enrolled in C2, S2 is enrolled in C1 and S3 is enrolled in C3.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)


1. Degree of a relationship set
The number of different entity sets participating in a relationship set is called as degree of a relationship set.

(i) Unary Relationship: When there is only ONE entity set participating in a relation, the relationship is called as unary relationship. For example, one person is married to only one person.


Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

(ii) Binary Relationship: When there are TWO entities set participating in a relation, the relationship is called as binary relationship.For example, Student is enrolled in Course.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)


(iii) n-ary Relationship: When there are n entities set participating in a relation, the relationship is called as n-ary relationship.

2. Cardinality
The number of times an entity of an entity set participates in a relationship set is known as cardinality.
Cardinality can be of different types
(i) One to one: When each entity in each entity set can take part only once in the relationship, the cardinality is one to one. Let us assume that a male can marry to one female and a female can marry to one male. So the relationship will be one to one.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Using Sets, it can be represented as:

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

(ii) Many to one: When entities in one entity set can take part only once in the relationship set and entities in other entity set can take part more than once in the relationship set, cardinality is many to one. Let us assume that a student can take only one course but one course can be taken by many students. So the cardinality will be n to 1. It means that for one course there can be n students but for one student, there will be only one course.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Using Sets, it can be represented as:

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

In this case, each student is taking only 1 course but 1 course has been taken by many students.
(iii) Many to many: When entities in all entity sets can take part more than once in the relationship cardinality is many to many. Let us assume that a student can take more than one course and one course can be taken by many students. So the relationship will be many to many.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Using sets, it can be represented as:

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

In this example, student S1 is enrolled in C1 and C3 and Course C3 is enrolled by S1, S3 and S4. So it is many to many relationships.

Participation Constraint
Participation Constraint is applied on the entity participating in the relationship set.

  1. Total Participation: Each entity in the entity set must participate in the relationship. If each student must enroll in a course, the participation of student will be total. Total participation is shown by double line in ER diagram.
  2. Partial Participation: The entity in the entity set may or may NOT participate in the relationship. If some courses are not enrolled by any of the student, the participation of course will be partial.

The diagram depicts the ‘Enrolled in’ relationship set with Student Entity set having total participation and Course Entity set having partial participation.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Using set, it can be represented as,


Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Every student in Student Entity set is participating in relationship but there exists a course C4 which is not taking part in the relationship.

Weak Entity Type and Identifying Relationship
As discussed before, an entity type has a key attribute which uniquely identifies each entity in the entity set. But there exists some entity type for which key attribute can’t be defined. These are called Weak Entity type.
For example, A company may store the information of dependants (Parents, Children, Spouse) of an Employee. But the dependents don’t have existence without the employee. So Dependent will be weak entity type and Employee will be Identifying Entity type for Dependant.
A weak entity type is represented by a double rectangle. The participation of weak entity type is always total. The relationship between weak entity type and its identifying strong entity type is called identifying relationship and it is represented by double diamond.
Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Different Types of Database Keys

  • Candidate Key
  • Primary Key
  • Super Key
  • Alternate Key
  • Foreign Key
  • Composite Key

Candidate Key

The minimal set of attributes that can uniquely identify a tuple is known as a candidate key. For Example, STUD_NO in STUDENT relation. 

  • It is a minimal super key.
  • It is a super key with no repeated data is called a candidate key.
  • The minimal set of attributes that can uniquely identify a record.
  • It must contain unique values.
  • It can contain NULL values.
  • Every table must have at least a single candidate key.
  • A table can have multiple candidate keys but only one primary key.
  • The value of the Candidate Key is unique and may be null for a tuple.
  • There can be more than one candidate key in a relationship. 

Example:
STUD_NO is the candidate key for relation STUDENT.

Table STUDENT

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

The candidate key can be simple (having only one attribute) or composite as well. 

Example:
{STUD_NO, COURSE_NO} is a composite
candidate key for relation STUDENT_COURSE.

Table STUDENT_COURSE

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Note: In SQL Server a unique constraint that has a nullable column, allows the value ‘null‘ in that column only once. That’s why the STUD_PHONE attribute is a candidate here, but can not be a ‘null’ value in the primary key attribute. 

Primary Key

There can be more than one candidate key in relation out of which one can be chosen as the primary key. For Example, STUD_NO, as well as STUD_PHONE, are candidate keys for relation STUDENT but STUD_NO can be chosen as the primary key (only one out of many candidate keys). 

  • It is a unique key.
  • It can identify only one tuple (a record) at a time.
  • It has no duplicate values, it has unique values.
  • It cannot be NULL.
  • Primary keys are not necessarily to be a single column; more than one column can also be a primary key for a table.

Example:
STUDENT table -> Student(STUD_NO, SNAME,
ADDRESS, PHONE) , STUD_NO is a primary key  

Table STUDENT

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Super Key

The set of attributes that can uniquely identify a tuple is known as Super Key. For Example, STUD_NO, (STUD_NO, STUD_NAME), etc. A super key is a group of single or multiple keys that identifies rows in a table. It supports NULL values. 

  • Adding zero or more attributes to the candidate key generates the super key.
  • A candidate key is a super key but vice versa is not true.
  • Super Key values may also be NULL.

Example:
Consider the table shown above.
STUD_NO+PHONE is a super key.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Alternate Key

The candidate key other than the primary key is called an alternate key.

  • All the keys which are not primary keys are called alternate keys.
  • It is a secondary key.
  • It contains two or more fields to identify two or more records.
  • These values are repeated.
  • Eg:- SNAME, and ADDRESS is Alternate keys

Example:

Consider the table shown above.
STUD_NO, as well as PHONE both,
are candidate keys for relation STUDENT but
PHONE will be an alternate key
(only one out of many candidate keys).

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Foreign Key

If an attribute can only take the values which are present as values of some other attribute, it will be a foreign key to the attribute to which it refers. The relation which is being referenced is called referenced relation and the corresponding attribute is called referenced attribute. The referenced attribute of the referenced relation should be the primary key to it.

  • It is a key it acts as a primary key in one table and it acts as 
  • secondary key in another table.
  • It combines two or more relations (tables) at a time.
  • They act as a cross-reference between the tables.

For example, DNO is a primary key in the DEPT table and a non-key in EMP

Example:

  • Refer Table STUDENT shown above.
  • STUD_NO in STUDENT_COURSE is a 
  • foreign key to STUD_NO in STUDENT relation.

Table STUDENT_COURSE

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

It may be worth noting that, unlike the Primary Key of any given relation, Foreign Key can be NULL as well as may contain duplicate tuples i.e. it need not follow uniqueness constraint. For Example, STUD_NO in the STUDENT_COURSE relation is not unique. It has been repeated for the first and third tuples. However, the STUD_NO in STUDENT relation is a primary key and it needs to be always unique, and it cannot be null. 

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Composite Key

Sometimes, a table might not have a single column/attribute that uniquely identifies all the records of a table. To uniquely identify rows of a table, a combination of two or more columns/attributes can be used.  It still can give duplicate values in rare cases. So, we need to find the optimal set of attributes that can uniquely identify rows in a table.

  • It acts as a primary key if there is no primary key in a table
  • Two or more attributes are used together to make a composite key.
  • Different combinations of attributes may give different accuracy in terms of identifying the rows uniquely.

Example:
FULLNAME + DOB can be combined
together to access the details of a student.

Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

Conclusion

In conclusion, the relational model makes use of a number of keys: Candidate keys allow for distinct identification, the Primary key serves as the chosen identifier, Alternate keys offer other choices, and Foreign keys create vital linkages that guarantee data integrity between tables. The creation of strong and effective relational databases requires the thoughtful application of these keys.

The document Entity, Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Database Management System (DBMS).
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
62 videos|66 docs|35 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Entity, Sets & Keys - Database Management System (DBMS) - Computer Science Engineering (CSE)

1. What is the ER Model?
Ans. The Entity-Relationship (ER) model is a conceptual model used in database design to represent the structure of a database. It depicts entities, attributes, relationships, and constraints, providing a clear and organized representation of the database schema.
2. What are entities in the ER Model?
Ans. Entities in the ER Model represent real-world objects or concepts that have distinguishable characteristics and can be uniquely identified. For example, in a university database, entities can include students, courses, professors, and departments.
3. What are sets in the ER Model?
Ans. In the ER Model, sets are used to group similar entities together based on their attributes and characteristics. They help in organizing the entities and provide a clear structure to the database. For example, in a banking system, sets can be created for customers, accounts, transactions, etc.
4. What are keys in the ER Model?
Ans. Keys in the ER Model are attributes or combinations of attributes that uniquely identify an entity within a set. They ensure that each entity has a distinct identifier, which is crucial for maintaining data integrity and avoiding duplication. For example, in a student database, the student ID can be used as a key to uniquely identify each student.
5. How does the ER Model help in database design?
Ans. The ER Model provides a visual representation of the database structure, allowing designers to easily understand and communicate the relationships and dependencies between entities. It helps in identifying the entities, attributes, and constraints that need to be considered while designing the database schema. Additionally, the ER Model assists in the creation of an efficient and well-organized database that accurately represents the real-world scenario it is designed for.
62 videos|66 docs|35 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

,

shortcuts and tricks

,

Viva Questions

,

MCQs

,

Entity

,

Summary

,

Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

,

Free

,

video lectures

,

practice quizzes

,

Important questions

,

mock tests for examination

,

Exam

,

pdf

,

study material

,

Semester Notes

,

Entity

,

Objective type Questions

,

Previous Year Questions with Solutions

,

Sets & Keys | Database Management System (DBMS) - Computer Science Engineering (CSE)

,

Sample Paper

,

ppt

,

past year papers

,

Entity

,

Extra Questions

;