Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Database Models

Database Models
• A model is representation of reality, ‘real world’ objects
events and their association.

Definition:
Data Model can be defined as “An integrated collection of
concepts for describing and manipulating data, relationship
between data and constraints on the data in an organization.”
Database Models
• Purpose of data model:
To represent data and to make the data understandable

Data model: defines logical structure of the database. It


determines how data can be stored and accessed. Different
models use different data structures for storing the database
on the server.
Database Models
– Hierarchical Model
– Network Model
– Relational Model
– Object Oriented Model
– E-R model
Relational Model
• Concept was proposed by Dr. E.F. Codd, researcher of IBM
in year 1960.
• Stores data in the form of tables
Relational Model consists of 3 components:
1. Set of relations and Set of domains that define the way
data can be represented (data structure)
2. Integrity rules that define the procedure to protect the
data. (Data integrity)
3. The operations that can be performed on the data. (data
manipulation)
Relational Model
• Relational model database is defined as database
that allows you to group its data items into one or
more independent tables that can be related to
one another by using fields common to reach
related table.
Relational Model
• Basic Terminology
Attributes --> Emp_code Name Year
Tuple --> 2100 Amar 1
2145 Deep 3
1012 Kumar 2
4521 Singh 6

1. Tuple
Each row of data is a tuple.
2. Cardinality of a relation
Number of tuple in a relationship is its cardinality
E.g. here cardinality is 4
Relational Model
• Basic Terminology
Attributes --> Emp_code Name Year
Tuple --> 2100 Amar 1
2145 Deep 3
1012 Kumar 2
4521 Singh 6
3. Degree of relationship
Each column in a tuple is called an attribute.
Number of attributes in a relationship is its degree.
E.g. here degree is 3
Relational Model
4. Domain
Domain is set of all values that an attribute may contain.

Domains are not data types.


Data type is physical concept and Domain is logical concept.
Exp1: Number is data type but Age is domain

Exp2: Street name and Surname: both are text but belong to
different domains
Relational Model
5. Body of a relation
Consists of an unordered set of zero or more tuples
6. Keys of a relation
It is a set of one or more columns whose combined values are
unique among all occurrences in a given table.
Basic keys:
a) Primary Key
Is an attribute or set of attributes that possess the property of
uniqueness and irreducibility (no subset should be unique)
Relational Model
Relational Model Properties
Alternative Terms in Relational Model
ER DIAGRAM
• ER model was introduced by Peter Chenn in 1976
• The ER model defines the conceptual (or logical) view
of a database.
• It is used for designing database.
• It works around real-wor ld entities and the relationships
among them
• A database schema in the ER Model can be
represented pictorially as ER diagrams
• An ER diagram maps well into a relational schema.
WHY ER DIAGRAM
ER Modeling Constructs
1. Entity
2. Attribute
3. Relationship
Entity
An Entity is a "thing" or “object" in the real world that is
distinguishable from other objects.

An entity can be anything that has an independent existence


and about which we collect data. It is also known as the entity
type.

Example: In a School database, the students, teachers, classes,


courses, or projects can be taken as an entity
Entity
Entities are represented by means of rectangles.

• Entities have attributes that give them their identity


• Example: Students have roll. no., names and addresses
• Entities becomes table in relational model
Entity Set
An Entity Set is a collection of similar type of entities that
share same attributes.
Example: a Student’s set may contain all the students of a
school;
A Teachers set may contain all the teachers of a school from all
faculties.
Entity Set
Entity sets need not be disjoint

Example: the entity set Employee (all employees of a bank)


and the entity set Customer (all customers of the bank) may
have members in common
Types of Entities
The following are the types of entities in DBMS −
Strong Entity
Its existence is not dependent on any other entity.
The strong entity has a primary key.

Weak entities are dependent on strong entity.


Types of Entities
Example of Entity in DBMS
<Professor>

Here, Professor_Name, Professor _Address and Professor _Salary


are attributes.
Professor_ID is the Key attribute (primary key)
Strong Entity
Strong Entity is represented by a single rectangle:

Continuing our previous example,


Professor is a strong entity here, as it has a key attribute
Professor_ID.
Weak Entity
The weak entity in DBMS do not have a primary key and are
dependent on the parent entity.
Weak Entity is represented by double rectangle
Weak Entity
Professor is a strong entity, and the primary key is Professor_ID.

However, another entity is Professor_Dependents, which is our


Weak Entity.
Example: strong and weak entity
Attribute
An entity is represented by a set of attributes
Attributes are used to describe the property of an entity

Example: a Student entity may have Roll_No, Name, DOB, Age,


Address, MobileNo as attribute
For each attribute, there is a set of permitted values, called
the domain of that attribute
Attribute
Example:
• a student 's name cannot be a numeric value.
• It has to be alphabetic.
• A student's age cannot be negative, etc.
• A student roll_no can be numeric between some range
• Attributes are represented by Ellipse

Attribute
Attribute
Attribute Types
• Simple and Composite attributes
• Single-valued and Multi-valued attributes
• Stored and Derived attributes
• Key Attribute
Attribute Types
Composite
Attribute Types
Attribute Types
Derived
Key Attribute
Attribute Type: Example
Relationships
• A Relationship is an association among entities For
example:
1. an employee works_at a department
2. a student enrolls in a course.
• Here, Works_at and Enrolls are called relationships.
• Relationships are represented by diamond-shaped box
Relationships
Relationship Set
A set of relationships of similar ty pe is called relationship
Set
The following relationship set "Enrolls(E1,E2,E3)" depicts:
S1 is enrolled in C2,S2 is enrolled in Cl and S3 is enrolled in
C3
Relationship Descriptive Attribute
Like entities, a relationship too can have attributes . These
attributes are called descriptive attributes
For instance, the depositor relationship set between entity
sets customer and account may have the attribute access-
date
Degree of Relationship
The number of different entity sets participating in a
relationship set is called as degree of a relationship set
1. Unary
2. Binary
3. Ternary
4. N-ary
Degree of Relationship
Unary Relationship:{degr ee = 1)
A unary relationship is only one entity participate in a
relationship, the relationship is ca lled as unary relationship.
1) For example,one person is married to only one
person
Degree of Relationship
Binary Relationship: (degree = 2 )
A binary relationship is when two entities participate in a
relationship, and is the most common relationship degree.
2) For example, Student is enrolled in Course
Degree of Relationship
Represented as
MCQ

You might also like