Docsity

DBMS-Unit - II Relational Data Model, Study notes of Database Management Systems (DBMS)

Toggle sidebar
bg1
—-------------Notes for DBMS—-------------------
Unit - II Relational Data Model
2.1 Relational Structure
The Relational Model organizes data in the form of tables called relations. It's the most
widely used model in DBMS (Database Management System).
A. Relation (Table)
∙ A relation is a named table consisting of rows and columns.
∙ It represents an entity set — a collection of similar objects.
�� Example: A STUDENT relation (entity set)
Roll_
No
101
102
103
Name
e
nder
Course_
ID C101
C102
C101
Riya
20
F
Moha
2
M
Sneha
22
F
Explanation:
∙ Each row represents a student.
∙ Each column is an attribute of the student.
B. Tuple (Row)
∙ A tuple is a single record in a relation.
∙ It represents an individual instance of an entity.
�� Example:
∙ (101, Riya, 20, F, C101) → 1 tuple in the STUDENT table
C. Attribute (Column)
∙ An attribute is a field in a table.
∙ Each attribute has:
o A name
o A data type (e.g., INTEGER, VARCHAR, DATE)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download DBMS-Unit - II Relational Data Model and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

—-------------Notes for DBMS—-------------------

Unit - II Relational Data Model

2.1 Relational Structure

The Relational Model organizes data in the form of tables called relations. It's the most widely used model in DBMS (Database Management System).

A. Relation (Table)

∙ A relation is a named table consisting of rows and columns. ∙ It represents an entity set — a collection of similar objects.

�� Example: A STUDENT relation (entity set) Roll_

No

101

102

103

Name e nder

Course_

ID C

C

C

Riya 20 F

Moha 2

M

Sneha 22 F

Explanation:

∙ Each row represents a student. ∙ Each column is an attribute of the student.

B. Tuple (Row)

∙ A tuple is a single record in a relation. ∙ It represents an individual instance of an entity.

�� Example:

∙ (101, Riya, 20, F, C101) → 1 tuple in the STUDENT table

C. Attribute (Column)

∙ An attribute is a field in a table. ∙ Each attribute has: o A name o A data type (e.g., INTEGER, VARCHAR, DATE)

�� Example:

∙ In the STUDENT relation: Roll_No, Name, Age, Gender, Course_ID are attributes.

1 | P a g e D. Domain

∙ The domain of an attribute is the set of valid values it can hold.

�� Example:

∙ Age domain: {18, 19, ..., 30} ∙ Gender domain: {Male, Female, Other}

�� If a value is outside the domain, it is invalid.

E. Entity

∙ An entity is a real-world object. ∙ An entity set is a collection of similar entities.

�� Example:

∙ A student (Riya) is an entity. ∙ The STUDENT table is the entity set.

2.2 Keys

Keys are used to uniquely identify data in a table.

A. Super Key

∙ A super key is any combination of attributes that uniquely identifies a row. ∙ It may contain extra attributes.

�� Example (STUDENT table):

∙ {Roll_No} ∙ {Roll_No, Name} ∙ {Roll_No, Name, Age} → all are super keys

B. Candidate Key

∙ A minimal super key.

3 | P a g e

2.3 Data Constraints –

In a relational database , data constraints are rules that ensure that only valid, consistent, and meaningful data is stored in the database.

Without constraints:

∙ Invalid data may enter the system (e.g., negative age, duplicate roll numbers). ∙ Relationships between data can break. ∙ Data quality and trust are compromised.

A. Domain Constraint (Attribute-Level Constraint)

✅ What is it?

∙ A domain is the set of valid values an attribute can take. ∙ A domain constraint ensures that attribute values must be from the defined domain.

✅ Purpose:

∙ Prevents invalid or meaningless data from being entered. ∙ Ensures type compatibility , ranges, and logical values.

�� Examples:

1. Age Domain Constraint:

∙ Attribute: Age ∙ Domain: Integer values from 18 to 30 Age

25

Valid? Why?

Within domain

Out of range

"Twenty"

Invalid age

Wrong data type

✅ Only numeric values between 18–30 allowed.

4 | P a g e

2. Gender Domain Constraint:

∙ Attribute: Gender ∙ Domain: {'Male', 'Female', 'Other'}

❌ “Unknown” → not allowed.

3. Date of Birth Constraint:

∙ Attribute: DOB ∙ Domain: Valid dates only.

❌ “32/13/2023” → not a valid date format.

4. Course_ID Format Constraint (Optional by domain rules):

∙ Suppose Course_ID must be in the format "C" followed by 3 digits:

✅ C101, C ❌ 101C, COURSE1 → Invalid

�� Real-Life Analogy:

Imagine filling an online form:

∙ Age: Must be between 18 and 30 → domain constraint. ∙ Email: Must follow correct email format → domain constraint. ∙ Gender: Dropdown menu allows only M/F/Other → domain constraint.

When inserting or updating a foreign key:

∙ The DBMS checks whether the value exists in the parent table. ∙ If not, the operation fails.

Real-Life Analogy:

Let’s say:

∙ STUDENT.Course_ID is like a course registration number. ∙ COURSE.Course_ID is like an official course catalog.

If a student tries to enroll in a non-existent course , it would be rejected in a real college — just like the DBMS blocks it.

6 | P a g e

2.4 Entity Relationship Model

The Entity-Relationship Model (ER Model) is a conceptual model for designing a databases. This model represents the logical structure of a database, including entities, their attributes and relationships between them.

∙ Entity: An objects that is stored as data such as Student , Course or Company.

∙ Attribute: Properties that describes an entity such as StudentID , CourseName , or EmployeeEmail.

∙ Relationship: A connection between entities such as "a Student enrolls in a Course ".

Components of ER Diagram

The graphical representation of this model is called an Entity-Relation Diagram (ERD).

ER Model in Database Design Process

We typically follow the below steps for designing a database for an application.

∙ Gather the requirements (functional and data) by asking questions to the database users.

∙ Create a logical or conceptual design of the database. This is where ER model plays a role. It is the most used graphical representation of the conceptual design of a database.

∙ After this, focus on Physical Database Design (like indexing) and external design (like views)

Why Use ER Diagrams In DBMS?

∙ ER diagrams represent the E-R model in a database, making them easy to convert into relations (tables).

7 | P a g e ∙ These diagrams serve the purpose of real-world modeling of objects which makes them intently useful.

∙ Unlike technical schemas, ER diagrams require no technical knowledge of the underlying DBMS used.

∙ They visually model data and its relationships, making complex systems easier to understand.

Symbols Used in ER Model

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

The entity type defines the structure of an entity, while individual instances of that type represent specific entities.

What is an Entity Set?

An entity refers to an individual object of an entity type, and the collection of all entities of a particular type is called an entity set. For example, E1 is an entity that belongs to the entity type "Student," and the group of all students forms the entity set.

In the ER diagram below, the entity type is represented as:

Entity Set

9 | P a g e We can represent the entity sets in an ER Diagram but we can't represent individual entities because an entity is like a row in a table, and an ER diagram shows the structure and relationships of data, not specific data entries (like rows and columns). An ER diagram is a visual representation of the data model, not the actual data itself.

Types of Entity

There are two main types of entities:

1. Strong Entity

A Strong Entity is a type of entity that has a key Attribute that can uniquely identify each

instance of the entity. A Strong Entity does not depend on any other Entity in the Schema for its identification. It has a primary key that ensures its uniqueness and is represented by a rectangle in an ER diagram.

2. Weak Entity

A Weak Entity cannot be uniquely identified by its own attributes alone. It depends on a strong entity to be identified. A weak entity is associated with an identifying entity (strong entity), which helps in its identification. A weak entity are represented by a double rectangle. The participation of weak entity types is always total. The relationship between the weak entity type and its identifying strong entity type is called identifying relationship and it is represented by a double diamond.

Example:

A company may store the information of dependents (Parents, Children, Spouse) of an Employee. But the dependents can't exist without the employee. So dependent will be a Weak Entity Type and Employee will be identifying entity type for dependent, which means it is Strong Entity Type.

Strong Entity and Weak Entity

Attributes in ER Model

Attributes are the properties that define the entity type. For example, for a Student entity Roll_No, Name, DOB, Age, Address, and Mobile_No are the attributes that define entity type Student. In ER diagram, the attribute is represented by an oval.

10 | P a g e

Attribute

Types of Attributes

Multivalued Attribute

4. Derived Attribute

An attribute that can be derived from other attributes of the entity type is known as a derived attribute. e.g.; Age (can be derived from DOB). In ER diagram, the derived attribute is represented by a dashed oval.

Derived Attribute

The Complete Entity Type Student with its Attributes can be represented as:

Entity and Attributes

12 | P a g e 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, the relationship type is represented by a diamond and connecting the entities with lines.

Entity-Relationship Set

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

Relationship Set

Degree of a Relationship Set

The number of different entity sets participating in a relationship set is called the degree of a relationship set.

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

13 | P a g e

One to One Cardinality

14 | P a g e Using Sets, it can be represented as:

Set Representation of One-to-One

2. One-to-Many

In one-to-many mapping as well where each entity can be related to more than one entity. Let us assume that one surgeon department can accommodate many doctors. So the Cardinality will be 1 to M. It means one department has many Doctors.

one to many cardinality

Using sets, one-to-many cardinality can be represented as:

Set Representation of One-to-Many 15 | P a g e

3. Many-to-One

When entities in one entity set can take part only once in the relationship set and entities in other entity sets 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.

many to one cardinality

Using Sets, it can be represented as:

Set Representation of Many-to-One

In this case, each student is taking only 1 course but 1 course has been taken by many students.

Many-to-Many Set Representation

17 | P a g e 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 to 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 students will be total. Total participation is shown by a double line in the 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 students, the participation in the 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.

Total Participation and Partial Participation

Using Set, it can be represented as,

Set representation of Total Participation and Partial Participation

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

How to Draw an ER Diagram

1. Identify Entities: The very first step is to identify all the Entities. Represent these entities in a Rectangle and label them accordingly.

18 | P a g e

2. Identify Relationships : The next step is to identify the relationship between them and represent them accordingly using the Diamond shape. Ensure that relationships are not directly connected to each other. 3. Add Attributes : Attach attributes to the entities by using ovals. Each entity can have multiple attributes (such as name, age, etc.), which are connected to the respective entity. 4. Define Primary Keys: Assign primary keys to each entity. These are unique identifiers that help distinguish each instance of the entity. Represent them with underlined attributes. 5. Remove Redundancies : Review the diagram and eliminate unnecessary or repetitive entities and relationships. 6. Review for Clarity : Review the diagram make sure it is clear and effectively conveys the relationships between the entities.