Hierarchical Model
•HierarchicalModelwasthefirstDBMSmodel.
•Thismodelorganizesthedatainthehierarchicaltreestructure.
•Thehierarchystartsfromtherootwhichhasrootdataandthenit
expandsintheformofatreeaddingchildnodetotheparent
node.
•Thismodeleasilyrepresentssomeofthereal-worldrelationships
likefoodrecipes,sitemapofawebsiteetc.
Example
Features of a Hierarchical Model
•One-to-manyrelationship:Thedatahereisorganisedinatree-likestructurewhere
theone-to-manyrelationshipisbetweenthedatatypes.Also,therecanbeonlyone
pathfromparenttoanynode.Example:Intheaboveexample,ifwewanttogoto
thenodesneakersweonlyhaveonepathtoreachtherei.ethroughmen'sshoes
node.
•Parent-ChildRelationship:Eachchildnodehasaparentnodebutaparentnode
canhavemorethanonechildnode.Multipleparentsarenotallowed.
•DeletionProblem:Ifaparentnodeisdeletedthenthechildnodeisautomatically
deleted.
•Pointers:Pointersareusedtolinktheparentnodewiththechildnodeandareused
tonavigatebetweenthestoreddata.Example:Intheaboveexamplethe'shoes'
nodepointstothetwoothernodes'womenshoes'nodeand'men'sshoes'node.
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.
•As it does not support more than one parent of the child node
so if we have some complex relationship where a child node
needs to have two parent node then that can't be represented
using this model.
•If a parent node is deleted then the child node is
automatically deleted.
Features of a Network Model
•AbilitytoMergemoreRelationships:Inthismodel,asthereare
morerelationshipssodataismorerelated.Thismodelhasthe
abilitytomanageone-to-onerelationshipsaswellasmany-to-
manyrelationships.
•Manypaths:Astherearemorerelationshipssotherecanbe
morethanonepathtothesamerecord.Thismakesdataaccess
fastandsimple.
•CircularLinkedList:Theoperationsonthenetworkmodelare
donewiththehelpofthecircularlinkedlist.Thecurrent
positionismaintainedwiththehelpofaprogramandthis
positionnavigatesthroughtherecordsaccordingtothe
relationship.
Advantages of Network Model
•Thedatacanbeaccessedfasterascomparedtothe
hierarchicalmodel.Thisisbecausethedataismorerelated
inthenetworkmodelandtherecanbemorethanonepathto
reachaparticularnode.Sothedatacanbeaccessedinmany
ways.
•Asthereisaparent-childrelationshipsodataintegrityis
present.Anychangeinparentrecordisreflectedinthechild
record.
Disadvantages of Network Model
•Asmoreandmorerelationshipsneedtobehandledthe
systemmightgetcomplex.
•So,ausermustbehavingdetailedknowledgeofthemodel
toworkwiththemodel.
•Anychangelikeupdation,deletion,insertionisvery
complex.
Relational Model
•RelationalModelisthemostwidelyusedmodel.
•Inthismodel,thedataismaintainedintheformofatwo-
dimensionaltable.
•Alltheinformationisstoredintheformofrowand
columns.
•Thebasicstructureofarelationalmodelistables.
•So,thetablesarealsocalledrelationsintherelational
model.
Features of Relational Model
•Tuples:Eachrowinthetableiscalledtuple.Arowcontains
alltheinformationaboutanyinstanceoftheobject.Inthe
aboveexample,eachrowhasalltheinformationaboutany
specificindividuallikethefirstrowhasinformationabout
John.
•Attributeorfield:Attributesarethepropertywhichdefines
thetableorrelation.Thevaluesoftheattributeshouldbe
fromthesamedomain.Intheaboveexample,wehave
differentattributesoftheemployeelikeSalary,Mobile_no,
etc.
Advantages of Relational Model
•Simple:Thismodelismoresimpleascomparedtothe
networkandhierarchicalmodel.
•Scalable:Thismodelcanbeeasilyscaledaswecanaddas
manyrowsandcolumnswewant.
•StructuralIndependence:Wecanmakechangesindatabase
structurewithoutchangingthewaytoaccessthedata.When
wecanmakechangestothedatabasestructurewithout
affectingthecapabilitytoDBMStoaccessthedatawecan
saythatstructuralindependencehasbeenachieved.
Disadvantages of Relational Model
•HardwareOverheads:Forhidingthecomplexitiesand
makingthingseasierfortheuserthismodelrequiresmore
powerfulhardwarecomputersanddatastoragedevices.
•BadDesign:Astherelationalmodelisveryeasytodesign
anduse.Sotheusersdon'tneedtoknowhowthedatais
storedinordertoaccessit.Thiseaseofdesigncanleadto
thedevelopmentofapoordatabasewhichwouldslowdown
ifthedatabasegrows.
Column Name Data Type Constraint
StudentID INT Primary Key
Name VARCHAR Not Null
DeptID INT Foreign Key
Example: College Database Schema
Let’s consider a schema for a simple College Database:
1. Student Table
Column Name Data Type Constraint
DeptID INT Primary Key
DeptName VARCHAR Unique
2. Department Table
Column Name Data Type Constraint
CourseID INT Primary Key
Title VARCHAR Not Null
DeptID INT Foreign Key
3. Course Table
Relationships
•Student.DeptID→ references Department.DeptID
•Course.DeptID→ references Department.DeptID
DATA DICTIONARY
DATA ABSTRACTION
Aspect Data Independence Data Abstraction
Definition
Protecting applications from
changes in schema or storage.
Hiding storage details and
showing only needed info.
Purpose
To allow changes without
rewriting applications.
To simplify interaction
between user and database.
Focus Change management. Information hiding.
Example
Adding a column without
changing queries.
User sees only name & email,
not storage details.
Types/Levels
Logical & Physical data
independence.
Physical, Logical & View levels.
Data Independence and Data Abstraction
ExampleofERModel
From theaboveexamplewecanseetherelationshipWORK_FORisbetweenentities
EMPLOYEEand DEPARTMENT.Itisasamplediagramastheoriginaldiagram includes
Many entitiesandrelationships.
EmpID, Ename, Salary are theattributesofEmployeeentity.
DeptID,DnamearetheattributesofDepartmententity.
Components
ENTITY
▶
▶
▶
An Entity maybean object with aphysical existence –a particularperson, car,
house,oremployee–or it maybe anobject witha conceptualexistence –a
company,ajob,orauniversitycourse.
An Entity type hasakeyattribute thatuniquely identifieseachentity intheentity
set.Butsomeentity typeexistsforwhichkeyattributescan’tbe defined.These
arecalledWeakEntitytypes.
AStrong Entityisa typeof entitythat has a keyAttribute.StrongEntitydoes not
dependonotherEntityinthe Schema.Ithasaprimarykey, thathelpsin
identifying ituniquely,and itis represented by arectangle.Thesearecalled
StrongEntityTypes.
One-to-OneRelationship
When onlyone instance of an entityis associatedwiththerelationship.For example,
astudent hasonlyone identification cardandanidentificationcardisgiventoone
person.
One-to-ManyRelationship
▶
▶
When onlyone instanceof the entityonthe left,andmore thanone instanceof an
entity on therightassociates withthe relationship
Forexample,a customercanplacemanyorders,butanorder cannot be placedby
manycustomers.
Many-to-OneRelationship
▶
▶
Whenmore thanone instance of theentityonthe left,andonlyone instanceofan
entity on therightassociates withthe relationship
Forexample,studentshave toopt for asingle course,butacourse canhave many
students.