Unit 2 Data Models Lecture
Unit 2 Data Models Lecture
Logical, Physical and Conceptual Model, E-R Model, Relation with UML class diagrams,
Alternate data models (Network Data Model, Hierarchical Data Model)
………………………………………………………………………………………………
A data model is an abstract view of the data referred to in the application being
developed.
DATABASE DESIGN:
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.
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:
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.
Mainly 3 types:
- 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.
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”,
- 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.
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.
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
Example:
We can represent the relationship between the shoes present on a shopping website in the
following way:
Example
Features of a Hierarchical Model
Network Model
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:
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
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.
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
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
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.
Simple Attributes:
Composite Attributes:
Derived Attributes:
Null Attributes:
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.
Example: The entity teacher has the property like teacher id, salary, age, etc.
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.
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
Disadvantages of ER Model
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.
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.
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
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?
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
Class Name:
Class Attributes:
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.
The figure below shows an inheritance example with two styles. Although the connectors
are drawn differently, they are semantically equivalent.
Association
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
one to one
one to many
many to many
Aggregation
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.
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