0% found this document useful (0 votes)
63 views

Unit 2 Data Models Lecture

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Unit 2 Data Models Lecture

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

Unit 2 – Data Models (4 hrs)

Logical, Physical and Conceptual Model, E-R Model, Relation with UML class diagrams,
Alternate data models (Network Data Model, Hierarchical Data Model)
………………………………………………………………………………………………

What Is Data Modeling

 A data model is an abstract view of the data referred to in the application being
developed.

DATABASE DESIGN:

The database design process can be divided into five steps.

1. Requirements Analysis:

 Here, the database designers collect information of the organization and analyzer,
the information to identify the user’s requirements.
 The database designers must find out what the users want from the database.

2. Conceptual Database Design:

Once the information is gathered in the requirements analysis step,


 A conceptual database design is developed and is used to develop a high level
description of the data to be stored in the database.
 This step is often carried out using the ER model, or a similar high-level data model.

3. Logical Database Design:

 In this step we convert the conceptual database design into a database schema
(Logical Database Design).
 We will only consider relational DBMSs, and therefore,
 Logical design means to convert an ER schema into a relational database schema.
 Once the logical scheme is defined designer consider the physical level
implementation and
 Finally provide certainsecurity measures.
4. Physical Database Design:

 This step may simply involve building indexes on some tables and clustering
some tables.

5. Security Design:

 The last step of database design is to include security features.


 This is required to avoid unauthorized access to database practice after all the five
steps.

Data Model

 Data Model gives us an idea that how the final system will look like after its complete
implementation.
 Used to show how data is stored, connected, accessed and updated in the database
management system.

There are many data models being used nowadays but the Relational model is the most widely
used model.

Data Model is a framework …..

 That helps in building the information system


 Facilitates easy access to the business data
 Helps management to take decisions
 Facilitate business to function efficiently

Types of Data Models

Mainly 3 types:

1. Conceptual Data Model:


- Represents the business data as seen in the real world and as understood by
businesses.
2. Logical Data Model:
- A logical data model is an extension of a conceptual model with more details.
3. Physical Data Model:

- It gives a technical view of the data i.e., the table name, column name, datatype,
constraints, indexes, primary key, triggers, stored procedures, etc.
1) Conceptual Data Model

 The main three components or elements of the Conceptual Data Model are
o Entity
o Attributes
o Relationship.

The two business entities are Customer and Product. The attributes of the two entities are
detailed in the Entity box.

The relationship between the two entities is the transaction -> ‘Sale’.

The relationship is many to many as one customer can have multiple products and one
product can have multiple customers.

Conceptual Model Diagram:

Some commonly used Relationship notations are:

Examples of cardinality: Relationship Notation


2) Logical Data Model

Key features:

 Logical data models give a detailed structure of the data elements and the data entity
relationships in a system from the business point of view.
 Logical Model lays the foundation for the physical database
 The relationship is presented more explicitly with details like,
o Primary key
o Foreign key
o Parent-child dependent entity type
o Cardinality of the relationship.

Extending the above example as explained in image “Data Modeling basic view”,

The business entities are Customer, Product, and Sale.

The relationship is many to many -

- As a customer and a product can have multiple sales and a sale can
have multiple customers and products. But every sale record should
have an existing product and an existing customer. So, Sales is a Child
entity, and Product and Customer are Parent Entities.

Logical Model Diagram:


3) Physical Data Model

Key features:

 A physical data model is the layout of the actual database with all its components and
services.
 This model depicts the actual database where the actual data is stored and is accessed in the
production environment when users use the application.
 This model is for developers and other users who desire to query the actual data
 It is based on technology and the choice that has been made for the database and the version of
the database i.e., ORACLE, SQL, INGRES, etc.
 It is an extension of the Logical model and has more details like table names for the Entity.
Column names are the attributes with more specifications like their exact datatype, length,
precision.
 It may display other attributes like primary key, indexes, security roles, constraints, stored
procedures, views, etc.

Physical Model Diagram:


Conceptual Vs Logical Vs Physical Data Model

Here is a table that describes each of the three levels.


Comparisons

Model Conceptual Logical Physical


Business Stakeholders & Data Architects & Database Administrator &
Owner / Creator
Requirement Team members Business Analysts Developers
Facilitates
Facilitates communication between Facilitates implementation
understanding of
the technical and non-technical of the actual entities with
business entities,
Purpose stakeholders in capturing all the actual business data and to
business flow, rules and
information / data, their rules and be used by the application in
helps in creation of
processes the production environment
actual physical database
Complexity Simple Complex Very Complex
Entity Names &
Yes, presented Yes, presented Not presented
Relationship
Entity Attributes Not presented Yes, presented Not presented
Keys (Primary &
Not presented Yes, presented Yes, presented
Foreign)
Table & Column
Not presented Not presented Yes, presented
Names
Column Data Type
Not presented Not presented Yes, presented
& Constraints

Some of other Data Models in DBMS are:

1. Hierarchical Model
2. Network Model
3. Entity-Relationship Model
4. Relational Model
5. Object-Oriented Data Model
6. Object-Relational Data Model
7. Flat Data Model
Hierarchical Model

 Hierarchical Model was the first DBMS model.


 This model organizes the data in the hierarchical tree structure.
 The hierarchy starts from the root which has root data and then it expands in the form of a
tree adding child node to the parent node.

Example:

We can represent the relationship between the shoes present on a shopping website in the
following way:

Example
Features of a Hierarchical Model

1. One-to-many relationship: The data here is organized in a tree-like structure where


the one-to-many relationship is between the datatypes.
2. Parent-Child Relationship: Each child node has a parent node but a parent node can
have more than one child node. Multiple parents are not allowed.
3. Deletion Problem: If a parent node is deleted then the child node is automatically
deleted.
4. Pointers: Used to link the parent node with the child node and are used to navigate
between the stored data.

Advantages of Hierarchical Model

 It is very simple and fast to traverse through a tree-like structure.


 Any change in the parent node is automatically reflected in the child node so, the
integrity of data is maintained.

Disadvantages of Hierarchical Model

 Complex relationships are not supported.


 If a parent node is deleted then the child node is automatically deleted.

Network Model

 This model is an extension of the hierarchical model.


 It was the most popular model before the relational model.
 This model is the same as the hierarchical model, the only difference is that a record
can have more than one parent. It replaces the hierarchical tree with a graph.

Example:

In the example below we can see that node student has two parents i.e. CSE Department and
Library. This was earlier not possible in the hierarchical model.
Example:

Features of a Network Model

1. Ability to Manage more Relationships: This model has the ability to manage one-to-
one relationships as well as many-to-many relationships.
2. Many paths: As there are more relationships so there can be more than one path to the
same record. This makes data access fast and simple.
3. Circular Linked List: The operations on the network model are done with the help of
the circular linked list.
Advantages of Network Model

 The data can be accessed faster as compared to the hierarchical model.


- There can be more than one path to reach a particular node.
- So the data can be accessed in many ways.

Disadvantages of Network Model

 As more and more relationships need to be handled the system might get complex.
o So, a user must be having detailed knowledge of the model to work with the
model.
 Any change like updation, deletion, insertion is very complex.

Object-Oriented Data Model

 The real-world problems are more closely represented through the object-oriented data
model.
 In this model, both the data and relationship are present in a single structure known
as an object.
 In this model, two are more objects are connected through links.

In the above example, we have two objects Employee and Department. All the data and
relationships of each object are contained as a single unit. The attributes like Name, Job_title of
the employee and the methods which will be performed by that object are stored as a single
object.

The two objects are connected through a common attribute i.e the Department_id and the

communication between these two will be done with the help of this common id.
Object-Relational Model

 As the name suggests it is a combination of both the relational model and the object-
oriented model.
 This model was built to fill the gap between object-oriented model and the relational
model.
 We can have many advanced features like we can make complex data types according to
our requirements using the existing data types.
 The problem with this model is that this can get complex and difficult to handle. So,
proper understanding of this model is required.

Example
Flat Data Model – MS Excel

 It is a simple model in which the database is represented as a table consisting of rows and
columns. To access any data, the computer has to read the entire table. This makes the
modes slow and inefficient.
RDBMS

RDBMS stands for Relational Database Management System.

 All modern database management systems like SQL, MS SQL Server, IBM DB2,
ORACLE, My-SQL, and Microsoft Access are based on RDBMS.
 It is based on the relational model introduced by E.F. Codd.

How it works

 Data is represented in terms of tuples (rows) in RDBMS.


 It contains several tables, and each table has its primary key.
 Due to a collection of an organized set of tables, data can be accessed easily in RDBMS.

Brief History of RDBMS

 From 1970 to 1972, E.F. Codd published a paper to propose using a relational database
model.
 RDBMS is originally based on E.F. Codd's relational model invention.

Following are the various terminologies of RDBMS:


Types of Attributes

Simple Attributes:

- Consists of a single atomic value


- Ex – roll, marks, salary etc..

Composite Attributes:

- Which can be decomposed ferther


- Ex – Name (Fname, Lname, Mname)
 Address (House_No, Street, City, State)

Single – Valued Attributes:

- Attributes that holds a single value


- Ex – City, Emp_ID, Salary etc

Multi – Valued Attributes:

- Attributes that holds multiple value


- Ex – Phone_No, Email_ID etc

Derived Attributes:

- Derived from another attribute


- Ex – Age (Derived from DOB)

Null Attributes:

- Attribute whose value is missing for a record


- Ex – If a record does not contain an assignment for the price attribute
Entity-Relationship Model

It is very easy for all technical and non-technical stakeholders to understand.

In this model, we represent the real-world problem in the pictorial form to make it easy for the
stakeholders to understand.

It is also very easy for the developers to understand the system by just looking at the ER
diagram.

We use the ER diagram as a visual tool to represent an ER Model.

ER diagram has the following three components:

 Entities: Entity is a real-world thing. It can be a person, place, or even a concept.


 Example: Teachers, Students, Course, Building, Department, etc are some of the entities
of a School Management System.
 Attributes: An entity contains a real-world property called attribute. This is the
characteristics of that attribute.

Example: The entity teacher has the property like teacher id, salary, age, etc.

 Relationship: Relationship tells how two attributes are related.


 Example: Teacher works for a department.
 In the diagram below,
o The two entities are Teacher and Subject.
o Some of the attributes of these entities are also depicted in the diagram.
o The relationship between the two entities is through ‘Teaching’.
ERD Notation

ER model Basics Concepts

For example, Suppose we design a school database. In this database, the student will be an
entity with attributes like address, name, id, age, etc. The address can be another entity with
attributes like city, street name, pin code, etc and there will be a relationship between them.
Component of ER Diagram

1. Entity:

An entity may be any object, class, person or place. In the ER diagram, an entity can be
represented as rectangles.

Consider an organization as an example- manager, product, employee, department etc. can be


taken as an entity.
a. Weak Entity

An entity that depends on another entity called a weak entity. The weak entity doesn't contain
any key attribute of its own. The weak entity is represented by a double rectangle.

2. Attribute

The attribute is used to describe the property of an entity. Eclipse is used to represent an
attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute

The key attribute is used to represent the main characteristics of an entity. It represents a primary
key. The key attribute is represented by an ellipse with the text underlined.

b. Composite Attribute

An attribute that composed of many other attributes is known as a composite attribute. The
composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.

c. Multivalued Attribute

An attribute can have more than one value. These attributes are known as a multivalued attribute.
The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.
d. Derived Attribute

An attribute that can be derived from other attribute is known as a derived attribute. It can be
represented by a dashed ellipse.

For example, A person's age changes over time and can be derived from another attribute like
Date of birth.

3. Relationship

A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.
Types of relationship are as follows:

a. One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is known as one to
one relationship.

For example, A female can marry to one male, and a male can marry to one female.

b. One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an entity on the
right associates with the relationship then this is known as a one-to-many relationship

For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.

c. Many-to-one relationship

When more than one instance of the entity on the left, and only one instance of an entity on the
right associates with the relationship then it is known as a many-to-one relationship

For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship

When more than one instance of the entity on the left, and more than one instance of an entity on
the right associates with the relationship then it is known as a many-to-many relationship

For example, Employee can assign by many projects and project can have many employees.

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

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

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

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

In many-to-many mapping, an entity in E1 is associated with any number of entities in E2, and
an entity in E2 is associated with any number of entities in E1.
Example:

In the above diagram, the entities are Teacher and Department. The attributes of Teacher entity
are Teacher_Name, Teacher_id, Age, Salary, Mobile_Number. The attributes of entity
Department entity are Dept_id, Dept_name. The two entities are connected using the
relationship. Here, each teacher works for a department.

Advantages of ER Model

 Simple: Conceptually ER Model is very easy to build. If we know the relationship


between the attributes and the entities we can easily build the ER Diagram for the model.
 Effective Communication Tool: This model is used widely by the database designers for
communicating their ideas.
 Easy Conversion to any Model: This model maps well to the relational model and can
be easily converted relational model by converting the ER model to the table. This model
can also be converted to any other model like network model, hierarchical model etc.

Disadvantages of ER Model

 No industry standard for notation: There is no industry standard for developing an ER


model. So one developer might use notations which are not understood by other
developers.
 Hidden information: Some information might be lost or hidden in the ER model. As it is
a high-level view so there are chances that some details of information might be hidden.
Some Examples of ERD

 Example
Example: School/College
Partial participation Each entity is involved in the relation
(Not all entity is involved in the relation)

Total participation
Relational Model

Relational Model is the most widely used model. In this model, the data is maintained in the
form of a two-dimensional table.

All the information is stored in the form of row and columns. The basic structure of a relational
model is tables. So, the tables are also called relations in the relational model.

Example: In this example, we have an Employee table.

Features of Relational Model

 Tuples: Each row in the table is called tuple. A row contains all the information about
any instance of the object. In the above example, each row has all the information about
any specific individual like the first row has information about John.
 Attribute or field: Attributes are the property which defines the table or relation. The
values of the attribute should be from the same domain. In the above example, we have
different attributes of the employee like Salary, Mobile_no, etc.

Advnatages of Relational Model

 Simple: This model is more simple as compared to the network and hierarchical model.
 Scalable: This model can be easily scaled as we can add as many rows and columns we
want.
 Structural Independence: We can make changes in database structure without changing
the way to access the data. When we can make changes to the database structure without
affecting the capability to DBMS to access the data we can say that structural
independence has been achieved.
Disadvantages of Relatinal Model

 Hardware Overheads: For hiding the complexities and making things easier for the user
this model requires more powerful hardware computers and data storage devices.
 Bad Design: As the relational model is very easy to design and use. So the users don't
need to know how the data is stored in order to access it. This ease of design can lead to
the development of a poor database which would slow down if the database grows.

But all these disadvantages are minor as compared to the advantages of the relational model.
These problems can be avoided with the help of proper implementation and organisation.

Relational

 Relational Model is the most popular model.


 In this model, the Entity information is represented as a table.
 All the attributes are represented as columns.
 The relationship between entities is represented by different standard notations.
 The primary key and foreign key of each entity are also mentioned.

Consider the following schema for a LibraryDatabase:


BOOK (Book_id, Title, Publisher_Name, Pub_Year)
BOOK_AUTHORS (Book_id, Author_Name)
PUBLISHER (Name, Address, Phone) BOOK_COPIES (Book_id, Branch_id, No-of_Copies)
BOOK_LENDING (Book_id, Branch_id, Card_No, Date_Out, Due_Date)
LIBRARY_BRANCH (Branch_id, Branch_Name, Address)
Write SQL queries to
1. Retrieve details of all books in the library – id, title, name of publisher, authors, number
of copies in each branch,etc.
2. Get the particulars of borrowers who have borrowed more than 3 books, but from Jan
2017 to Jun2017
3. Delete a book in BOOK table. Update the contents of other tables to reflect this data
manipulationoperation.
4. Create a view of all books and its number of copies that are currently available in the
Library.
UML Class Diagram
Unified Modeling Language (UML)

 The UML is used for developing object oriented software and the software development
process

The UML Class diagram is a graphical notation used to construct and visualize object
oriented systems.

A static structure diagram that describes the structure of a system by showing the system's:

 classes,
 their attributes,
 operations (or methods),
 and the relationships among objects.

What is a Class?

 A Class is a blueprint for an object.


 In fact, classes describe the type of objects.
 An object is an instance of a class and object
o - Objects have states and behaviors.

Example

 A dog has
o States - color, name, breed etc..
o Behaviors -wagging, barking, eating. An object is an instance of a class.
UML Class Notation

 A class represents a concept which encapsulates state (attributes) and behavior


(operations).
 Each attribute has a type.
 Each operation has a signature.
 The class name is the only mandatory information.

Class Name:

 The name of the class appears in the first partition.

Class Attributes:

 Attributes are shown in the second partition.


 The attribute type is shown after the colon.
 Attributes map onto member variables (data members) in code.

Class Operations (Methods):

 Operations are shown in the third partition. They are services the class provides.
 The return type of a method is shown after the colon at the end of the method signature.
 Operations map onto class methods in code

Class Visibility

 The +, - and # symbols before an attribute and operation name in a class denote the
visibility of the attribute and operation.

 + denotes public attributes or operations


 - denotes private attributes or operations
 # denotes protected attributes or operations
Perspectives of Class Diagram

A diagram can be interpreted from various perspectives:

 Conceptual: represents the concepts in the domain


 Specification: focus is on the interfaces of Abstract Data Type (ADTs) in the software
 Implementation: describes how classes will implement their interfaces

As we mentioned above, the class name is the only mandatory information.

Relationships between classes

A class may be involved in one or more relationships with other classes.

A relationship can be one of the following types:


Inheritance (or Generalization):

 Represents an "is-a" relationship.

The figure below shows –

- An example of inheritance hierarchy.


- SubClass1 and SubClass2 are derived from SuperClass.
- The relationship is displayed with a hollow arrowhead that points from the child
element to the parent element.

Inheritance Example - Shapes

 The figure below shows an inheritance example with two styles. Although the connectors
are drawn differently, they are semantically equivalent.
Association

 Associations are relationships between classes in a UML Class Diagram.


 They are represented by a solid line between classes.
 Associations are typically named using a verb or verb phrase which reflects the real
world problem domain.

Simple Association

 A structural link between two peer classes.


 There is an association between Class1 and Class2

The figure below shows an example of simple association.

There is an association that connects the <<control>> class Class1 and <<boundary>> class
Class2. The relationship is displayed as a solid line connecting the two classes.

Cardinality

Cardinality is expressed in terms of:

 one to one
 one to many
 many to many
Aggregation

 A special type of association.

 It represents a "part of" relationship.


 Class2 is part of Class1.
 Many instances (denoted by the *) of Class2 can be associated with Class1.
 Objects of Class1 and Class2 have separate lifetimes.

The figure below shows an example of aggregation. The relationship is displayed as a solid line
with a unfilled diamond at the association end, which is connected to the class that represents the
aggregate.

Composition

 A special type of aggregation where parts are destroyed when the whole is destroyed.
 Objects of Class2 live and die with Class1.
 Class2 cannot stand by itself.

The figure below shows an example of composition. The relationship is displayed as a solid line
with a filled diamond at the association end, which is connected to the class that represents the
whole or composite.

Dependency

An object of one class might use an object of another class in the code of a method. If the object
is not stored in any field, then this is modeled as a dependency relationship.

 A special type of association.


 Exists between two classes if changes to the definition of one may cause changes to the
other (but not the other way around).
 Class1 depends on Class2
The figure below shows an example of dependency. The relationship is displayed as a dashed
line with an open arrow.

The figure below shows another example of dependency.

The Person class might have a hasRead method with a Book parameter that returns true if the
person has read the book (perhaps by checking some database).

Realization

Realization is a relationship between the blueprint class and the object containing its respective
implementation level details.

For example, the Owner interface might specify methods for acquiring property and disposing
of property. The Person and Corporation classes need to implement these methods, possibly in
very different ways.
Class Diagram Example: Order System

Class Diagram Example: GUI

A class diagram may also have notes attached to classes or relationships.

You might also like