Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 72

Data Model can be defined as an integrated collection of

concepts for describing and manipulating data,


relationships between data, and constraints on the data in
an organization.
A data model comprises of three components:

A structural part, consisting of a set of rules according


to which databases can be constructed.
A manipulative part, defining the types of operation
that are allowed on the data (this includes the operations
that are used for updating or retrieving data from the
database and for changing the structure of the
database). 
 Possibly a set of integrity rules, which ensures that
the data is accurate.
A database model defines the logical design of data. The
model also describes the relationships between different
parts of the data.
Data models define how data is connected to each other
and how they are processed and stored inside the system.
In the history of database design, three models have been
in use:
 the hierarchical model,
 the network model and
 the relational model.
 A model is a representation of reality, ‘real world’ objects
and events and their associations.
A model is a collection of tools for describing
 Data
 Data relationships
 Data semantics
 Data constraints
Various models falls into three different categories:
 Object-based data models
 Record Based Data Models
 Physical Data Models
 Use the concept of entities, attributes and relationships.
 Used to describe data at the logical and view level.
 It provides flexible structuring capabilities.
 The most widely known ones are:
 The Entity-Relationship Model
 The Object-Oriented Model.
It consists of basic objects called “Entities”, and
“Relationships” among these objects.
An entity is a thing or object in the real world that is
distinguishable from other objects.
Entities are described by set of attributes.
Entities are the principal data object about which info is to
be collected.
A relationship is association among several entities.
A database is modeled as a collection of entities and
relationship among entities. 
Basic constructs of ER Model
 Entities
 Entity set (Set of entities of same type that share the
same properties)
 Relationships
 Attributes (Describe the properties of entity)
Simple Attribute(Atomic Attributes)
Compound/Composite Attribute
Derived Attribute
Multivalued Attribute
 Degree of relationship
No. of entities associated with the relationship (n-ary)
 Cardinality (Mapping)
Types of Attributes
Simple attribute − Simple attributes are atomic values, which cannot be
divided further. For example, a student's phone number is an atomic value
of 10 digits.
Composite attribute − Composite attributes are made of more than one
simple attribute. For example, a student's complete name may have
first_name and last_name.
Derived attribute − Derived attributes are the attributes that do not exist
in the physical database, but their values are derived from other attributes
present in the database. For example, average_salary in a department
should not be saved directly in the database, instead it can be derived. For
another example, age can be derived from data_of_birth.
Single-value attribute − Single-value attributes contain single value. For
example − Social_Security_Number.
Multi-value attribute − Multi-value attributes may contain more than
one values. For example, a person can have more than one phone number,
email_address, etc.
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 a set of all
entities is called as an 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: 
Attribute(s):
Attributes are the properties that define the entity type.
For example, Roll_No, Name, DOB, Age, Address,
Mobile_No are the attributes that define entity type
Student. In ER diagram, the attribute is represented by
an oval.
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.
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.
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, a multivalued
attribute is represented by a double oval.
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.
 
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.
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 is enrolled in C1, and S3 is enrolled in
C3.  
Examples
A Relationship describes relations between entities.
Relationship is represented using diamonds.

There are different types of relationship that exist between


Entities.
Unary Relationship
Binary Relationship
Recursive Relationship
Ternary Relationship
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. 
Binary Relationship – 
When there are TWO entities set participating in a
relationship, the relationship is called a binary relationship.
For example, a Student is enrolled in a Course. 
n-ary Relationship –
When there are n entities set participating in a
relation, the relationship is called an an n-ary
relationship.
One to One 
One to Many
Many to One
Many to Many
One to one cardinality (One student has one
Address/Contact No.)
One to many cardinality (One student registered in
many courses)
(A department has many employees)
Many to one cardinality (Many employees are
working in one dept.)
Many to Many (Employees can be assigned to more
than two projects at a time)
Objects that contains the same types of values and the
same methods are grouped together into classes.
Like ER model OODM is based on collection of objects.
Object contains values stored in instance variable within
the object.
It is used to describe data at the logical and view level.

Record based models are so named because the database


is structured in fixed format records of several types.
 Relational Model
 Network Model
 Hierarchal Model
Relational data model is the primary data model,
which is used widely around the world for data
storage and processing.
It stores data in the form of tables.
This concept was proposed by E.F. Codd, a researcher
of IBM in year 1960s.
It uses a collection of tables to represent both data and
relationship among the data.
Each table has multiple columns and each column has
unique name.
Tables − In relational data model, relations are saved
in the format of Tables. This format stores the
relation among entities. A table has rows and
columns, where rows represents records and columns
represent the attributes.
Tuple − A single row of a table, which contains a
single record for that relation is called a tuple.
Relation instance − A finite set of tuples in the
relational database system represents relation
instance. Relation instances do not have duplicate
tuples.
Relation schema − A relation schema describes the
relation name (table name), attributes, and their
names.
Relation key − Each row has one or more attributes,
known as relation key, which can identify the row in
the relation (table) uniquely.
Attribute domain − Every attribute has some pre-
defined value scope, known as attribute domain.
Tuple of a relation (Each row is called aa tuple)
Cardinality of a relation (No. of tuples in a relation)
Degree of a relation (No. of attributes in a relation)
Domain (Set of all possible values that an attribute
my validly contain)
Keys of a Relation
 Primary Key
 Foreign Key
Operations in Relational Model
 Insert operation
 Update operation
 Delete operation
 Record retrieval
Organizes data in a tree structure (parent and child data).
Each entity has only one parent but can have several
children.
At the top of the hierarchy, there is one entity, which is
called the root.
1:N mapping between record types.
Advantages:
 Simplicity (Conceptually Simple)
 Data security
 Data Integrity
 Efficiency (Speed of access is faster because of the
predefined data paths)
Disadvantages:
 implement complexity 
 database management problem 
 programming complexity 
 implementation limitation 
Tree representing the relationship between STUDENT,
FACULTY and CLASS.
The root node chosen is faculty, CLASS as a child of
faculty and STUDENT as a child of class.
The cardinality between CLASS and FACULTY is one
to many cardinality as a FACULTY teaches one or more
CLASS.
The cardinality between a CLASS and a STUDENT is
also one to many cardinality because a CLASS has many
STUDENTS.
• In the network model, the entities are organized in a
graph, in which some entities can be accessed through
several paths.
• Some data modeled with more than one parent per child.
• Permits modeling of many-to-many relationships in data.
• It is represented by collection of records and relationship
among data is represented by links..
• Advantages:
• Easy to access data
• Can handle more relationship types
• Conceptually simple
• Data Integrity

• Disadvantages
• System complexity (Pointers)
• Operational Anomalies (Change in any record require large
number of pointers adjustments)
• Absence of structural independence.
 In the relational model, data is organized in two-dimensional
tables called relations.
E-R Model Relational Model
It represents the
It represents the
collection of objects
collection of Tables and
Basic called entities and
the relation between
relation between those
those tables.
entities.

Entity Relationship Model Relational Model


describe data as Entity describes data in a table
Describe
set, Relationship set and as Domain, Attributes,
Attribute. Tuples.

E-R Model is easier to Comparatively, it is less


understand the easy to derive a relation
Relationship
relationship between between tables in
entities. Relational Model.
Relational Model does
E-R Model describes
Mapping not describe mapping
Mapping Cardinalities.
cardinalities.
Constraints are the rules enforced on data columns on
table. These are used to limit the type of data that can
go into a table. This ensures the accuracy and reliability
of the data in the database.
The whole purpose of constraints is to maintain the
data integrity during an update/delete/insert into a
table.
Constraints could be column level or table level.
Column level constraints are applied only to one
column, whereas table level constraints are applied to
the whole table.
the values of individual columns are valid.
In a table, rows have a valid primary key or unique key
values.
in a dependent table, rows have valid foreign key values
that reference rows in a parent table.
Domain Constraints
Tuple Uniqueness Constraints
Key Constraints
Single Value Constraints
Integrity Rule 1 (Entity Integrity Rule or
Constraint)
Integrity Rule 2 (Referential Integrity Rule or
Constraint)
General Constraints
Domain Constraints specifies that what set of values an
attribute can take. Value of each attribute X must be an
atomic value from the domain of X.
Tuple Uniqueness Constraints if in a relation, tuple
uniqueness constraint is applied, then all the rows of that
table must be unique i.e. it does not contain the duplicate
values.
Key Constraints Keys are attributes or sets of attributes that
uniquely identify an entity within its entity set. Primary Key
must have unique and not null values in the relational table.
Single Value Constraints Single value constraints refers
that each attribute of an entity set has a single value. If the
value of an attribute is missing in a tuple, then we cal fill it
with a “null” value.
Integrity Rule 1 : The Integrity Rule 1 is also called
Entity Integrity Rule or Constraint. This rule states that no
attribute of primary key will contain a null value.
Integrity Rule 2 : The integrity Rule 2 is also called the
Referential Integrity Constraints. This rule states that if a
foreign key in Table 1 refers to the Primary Key of Table
2.
General Constraints: General constraints are like
CHECK Constraints or the Range Constraints etc.
 Check constraints can ensure that only specific values are
allowed in certain column.
 Range Constraints is implemented by BETWEEN and
NOT BETWEEN. For example, if it is a requirement that
student ages be within 16 to 35, then we can apply the range
constraints for it.
SQL Constraints are rules used to limit the type of data that
can go into a table, to maintain the accuracy and integrity of
the data inside table.
Constraints can be divided into following two types,
Column level constraints : limits only column data
Table level constraints : limits whole table data
Following are commonly used constraints available
in SQL:
 NOT NULL Constraint: Ensures that a column cannot have
NULL value.
 DEFAULT Constraint: Provides a default value for a
column when none is specified.
 UNIQUE Constraint: Ensures that all values in a column
are different. It can be a NULLL.
 PRIMARY Key: Uniquely identified each rows/records in a
database table.
 FOREIGN Key: Uniquely identified a rows/records in any
another database table.
 CHECK Constraint: The CHECK constraint ensures that
all values in a column satisfy certain conditions.
 By default, a column can hold NULL values. If you do not
want a column to have a NULL value, then you need to
define such constraint on this column specifying that
NULL is now not allowed for that column.
 A NULL is not the same as no data, rather, it represents
unknown data.
The DEFAULT constraint provides a default value to a
column when the INSERT INTO statement does not
provide a specific value.
The UNIQUE Constraint prevents two records from
having identical values in a particular column. In the
CUSTOMERS table, for example, you might want to
prevent two or more people from having identical
age.
UNIQUE constraint ensures that a field or column will
only have unique values. A UNIQUE constraint field will
not have duplicate data.
UNIQUE constraint can be applied at column level or
table level.
If CUSTOMERS table has already been created, then to add a UNIQUE constraint to
AGE column, you would write a statement similar to the following:
ALTER table customer add UNIQUE ( AGE);
 A primary key is a field in a table which uniquely identifies each
row/record in a database table. Primary keys must contain unique
values. A primary key column cannot have NULL values.
 A table can have only one primary key, which may consist of single or
multiple fields. When multiple fields are used as a primary key, they
are called a composite key.
 If a table has a primary key defined on any field(s), then you can not
have two records having the same value of that field(s).
 A foreign key is a key used to link two tables together.
This is sometimes called a referencing key.
 Foreign Key is a column or a combination of columns
whose values match a Primary Key in a different table.
 The relationship between 2 tables matches the
Primary Key in one of the tables with a Foreign Key in
the second table.
 The CHECK Constraint enables a condition to check the
value being entered into a record. If the condition
evaluates to false, the record violates the constraint and
isn't entered into the table.

You might also like