1.7 Data Models
1.7 Data Models
Data Models
by
GOWRU BHARATH KUMAR
M.Tech, (Ph.D)
Assistant Professor
Data Model
• Data Model gives us an idea that how the final system will look like after its
complete implementation.
(Or)
• It defines the data elements and the relationships between the data elements.
(Or)
• Data Models are used to show how data is stored, connected, accessed and updated
in the database management system.
• Here, we use a set of symbols and text to represent the information so that members of
the organization can communicate and understand it.
• Though there are many data models being used nowadays but the Relational model is
the most widely used model. Apart from the Relational model, there are many other
types of data models.
Hierarchical Model
Hierarchical Model
• 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.
• Deletion Problem: If a parent node is deleted then the child node is automatically deleted.
• Pointers: Pointers are used to link the parent node with the child node and are used to
navigate between the stored data. Example: In the above example the 'shoes' node points to
the two other nodes 'women shoes' node and 'men's shoes' node.
Advantages & Disadvantages of Hierarchical
Model
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.
• 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.
• Circular Linked List: The operations on the network model are done with
the help of the circular linked list. The current position is maintained with
the help of a program and this position navigates through the records
according to the relationship.
Advantages & Disadvantages of Network
Model
Advantages of Network Model
• The data can be accessed faster as compared to the hierarchical model. This is
because the data is more related in the network model and there can be more than
one path to reach a particular node. So the data can be accessed in many ways.
• As there is a parent-child relationship so data integrity is present. Any change in
parent record is reflected in the child record.
please click on
https://www.youtube.com/watch?v=YFk-IXBJeQ8&t=1205s
Relational Model
Relational Model
• Tuples/ Rows/ Records: 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 Alex.
• Fields/ Columns/Attributes: 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 studente like sid, sname,sage, sclass, ssection , etc.
Advantages 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 Relational 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 organization.
create a table using SQL
• The create table statement is used to define a new table.
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Now we will create the student table with the fields sid, name, login, age, gpa.
Query: CREATE TABLE Students
( sid CHAR(20),
name CHAR(30),
login CHAR(20),
age INTEGER,
gpa REAL);
Inserting data into table
• The table is created with the fields sid, name, login, age, gpa.
• Now we will insert the data into the table. (we can insert a single tuple into
the students table as follows)
Query:
insert into students (sid, name, login, age, gpa) values (1, ‘bharath’,
‘[email protected]’, 29, 7.1)
insert into students (sid, name, login, age, gpa) values (‘2’, ‘kumar’,
‘[email protected]’, 19, 9.1)
insert into students (sid, name, login, age, gpa) values (‘3’, ‘raju’, ‘[email protected]’,
17, 5.1)
1) Students(sid: string, name: string, login: string, age: integer, gpa: real)
2) Faculty(fid: string, fname: string, sal: real)
3) Courses( cid: string, cname: string, credits: integer)
4) Rooms(no: integer, address: string, capacity: integer)
5) Enrolled (sid: string, cid: string, grade: string)
6) Teaches(fid: string, cid: string)
7) Meets_In( cid: string, rno: integer, time: string)
For watching/ Explanation
• please click on
https://www.youtube.com/watch?v=Qq7s6HibSCg&t=186s
Object-Oriented Data Model
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, real world problems are represented as objects with different
attributes. All objects have multiple relationships between them.
• In this model, two or more objects are connected through links. We use this
link to relate one object to other objects.
• Basically, it is combination of Object Oriented programming and
Relational Database Model
Example-1
Components of Object Oriented Data Model
• Objects: An object is an abstraction of a real world entity or we can say it is an
instance of class. Objects encapsulates data and code into a single unit which
provide data abstraction by hiding the implementation details from the user.
For example: Instances of student, doctor, engineer in above figure.
• Attribute: An attribute describes the properties of object.
For example: Object is STUDENT and its attribute are Roll no, Branch in the
Student class.
• Methods: Method represents the behavior of an object. Basically, it represents
the real-world action.
For example: Finding a STUDENT marks in above figure as Setmarks().
• Class: A class is a collection of similar objects with shared structure i.e.
attributes, behavior i.e. methods. An object is an instance of class.
For example: Person, Student, Doctor, Engineer in above figure.
• Inheritance: By using inheritance, new class can inherit the attributes and
methods of the old class i.e. base class.
For example: as classes Student, Doctor and Engineer are inherited from the base
class Person.
Example-2
In the below 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.
Advantages & Disadvantages of Object
Oriented Data Model
Advantages of Object Oriented Data Model
• Codes can ne reused due to inheritance.
• Easily understandable.
• Cost of maintenance can reduced due to reusability of attributes and
functions because of inheritance.