jan. 2008 yangjun chen acs-3902 1 hierarchical dbmsoutline hierarchical database management systems...
TRANSCRIPT
Jan. 2008 Yangjun Chen ACS-3902 1
Hierarchical DBMSOutline
Hierarchical Database Management Systems
•Hierarchical Schemas•record type•parent-child relationship•hierarchical occurrence trees•linearized form of hierarchical occurrence•Virtual parent-child relationships
•Data definition in the hierarchical model•Data manipulation language for the hierarchical model
Jan. 2008 Yangjun Chen ACS-3902 2
Hierarchical DBMS
departmentdname dnumber mgrname mgrstartdate
employeename ssn bdate address
projectpname pnumber plocation
•A hierarchical schema consists of record types and PCR types.- A record is a collection of field values.- Records of the same type are grouped into record types.- A PCR type (parent-child relationship type) is a 1:N relationship
betweentwo record types.
•A hierarchical database schema consists of a number ofhierarchical schemas.
Hierarchical Schema
PCR
Jan. 2008 Yangjun Chen ACS-3902 3
Hierarchical DBMS
•PCR occurrence- Each PRC occurrence relates a record of a type (e.g., a department) to
somerecords of another type (e.g., employee).
Hierarchical Schema
PCR type: PCR occurrences:
research
WongSmith Narayan
administration
Zelaya Wallace Jabbar
research
Product2Product1 Product3
administration
Computerization ...
Department
Employee
Department
Project
Jan. 2008 Yangjun Chen ACS-3902 4
Hierarchical DBMS
•Properties of a Hierarchical Schema
1. One record type, called the root of the hierarchical schema, does not not participate as a child record type in any PCR type.
2. Every record type except the root participants as a child record type inexactly one PCR type.
3. A record type can participate as parent record type in any number(zero or more) of PCR types.
4. A record type that does not participate as parent record type in any PCRis called a leaf of the hierarchical schema.
5. If a record type participate as parent in more than one PCR type, then itschild record types are ordered. The order is displayed, by convention,
fromleft to right in a hierarchical diagram.
Hierarchical Schema
Jan. 2008 Yangjun Chen ACS-3902 5
Hierarchical DBMS
•Hierarchical occurrenceEach hierarchical occurrence, called an occurrence tree, is atree structure whose root is a single record from some recordtype. Each subtree of the root is again a hierarchical
occurrence.
- type indicator
Hiearchical Schema
departmentdname dnumber mgrname mgrstartdate
employeename ssn bdate address
projectpname pnumber plocation
D
E
P
T S W
dependent supervisee worker
Jan. 2008 Yangjun Chen ACS-3902 6
Hierarchical DBMS
- hierarchical occurrence
Hiearchical Schema
Level 1:
D AdministrationLevel 0:
Level 2:
E Zalaya E Wallace E Jabbar P computerization P new-benefit
T Abner S Zalaya S Jabbar W Wong W Zalaya W Jabbar W Zalaya
Jan. 2008 Yangjun Chen ACS-3902 7
Hierarchical DBMS
- linearized form of a hierarchical occurrenceprocedure Pre_order_traversal (root_record)
beginoutput(root_record);if no child node then return;else for each child_record of root_record in left to right order
do Pre_order_traversal (child_record)
end
Hiearchical Schema
D adminitratorE ZelayaE WallaceT AbnerS ZelayaS Jabbar E JabbarP compuerizationW WongW ZelayaP new-benefitW JabbarW Zelaya
Jan. 2008 Yangjun Chen ACS-3902 8
Hierarchical DBMS
•Virtual Parent-child Relationships- Problems with hierarchical model
1. M:N relationshipcauses redundancy
2. The case where a record type participates as child in more than one
PCR typecauses redundancy
3. N-ary relationships with more than two participating record typecan not be modelled
- Method dealing with the three problems:virtual record typevirtual PCR relationship
Virtual PCR
Jan. 2008 Yangjun Chen ACS-3902 9
Hierarchical DBMS
•Virtual Parent-child Relationships- virtual record type
A virtual (or pointer) record type VC is a record type with the property thateach of its records contains a pointer to a record of another type VP.VC plays the role of “virtual child” and VP of ‘virtual parent” in a “virtualparent-child relationship” (VPCR).
A record of a VC type is a pointer to a record of some VP type.A record of a VP type is a “real” record.
Example: M:N relationship between Employee and Project:
Virtual PCR
Project Employee
Epointer
P
Y
E Employee Project
Ppointer
E
R
P
VC
VP
Jan. 2008 Yangjun Chen ACS-3902 10
Hierarchical DBMS
•Virtual Parent-child Relationships- intersection data in a virtual record
An employee may participate in several projects. But for each project, he/she
may work for different hours per week.Therefore, the data representing “different hours per week” should beincluded in the virtual records since each pointer to an employee record
mayhave a different value. Such data are called intersection data.
- VPCRThe relationship between a virtual child and the corresponding virtual
parentis called a Virtual Parent-Child-Relationship.
Virtual PCR
Jan. 2008 Yangjun Chen ACS-3902 11
Hierarchical DBMS
•Virtual Parent-child Relationships- Example:
The relationship:
Virtual PCR
ProjectABCD
Employees working on the projectE1, E3, E5E2, E4, E6E1, E4E2, E3, E4, E5
can be stored as follows:
Jan. 2008 Yangjun Chen ACS-3902 12
Hierarchical DBMS
•Virtual Parent-child Relationships- Example:
Virtual PCR
A E1
E2
E3
E4
E5
E6
Ep1, 10 Ep2, 8 Ep3, 5
B
Ep4, 20 Ep5, 8 Ep6, 30
C
Ep7, 6 Ep8, 9
D
Ep10, 3 Ep11, 7 Ep12, 25Ep9, 20
Jan. 2008 Yangjun Chen ACS-3902 13
Hierarchical DBMS
dependent
Dept_locations
employee
department
project
ERD for Chapter 6 database example
1
1
1
1
n
n
nn
nn
m
1
11
Works on
Virtual PCR
Jan. 2008 Yangjun Chen ACS-3902 14
Hierarchical DBMS
•Virtual Parent-child Relationships- Hierarchical schema using VPCR - for a Company
database
Virtual PCR
Department
Dname Dnum
Project
Pname … ...Dlocation
Location
DemployeeEPTR
DmanagerMPTR Pworker
Hours WPTR
Employee
Ename Minit … ...
EsuperviseeSPTR
Dependent
DEPname Minit ...
D E
L P
Y
M W
S
T
StartDate
Jan. 2008 Yangjun Chen ACS-3902 15
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Hierarchical data definition language (HDDL)
•record typedata item of a record typekey clause
•virtual record typevirtual parent
•CHILD NUMBER clause (the left-to-right order)•ORDER BY clause
(the order of individual records of the same record type)
sequence key
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 16
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
SCHEMA NAME = COMPANY
HIERARCHIES = HIERARCHY1, HIERARCHY2
RECORDNAME = EMPLOYEETYPE = ROOT OF HIERARCHY2DATA ITEMS =
FNAME CHARACTER 15MINIT CHARACTER 1LNAME CHARACTER 15SSN CHARACTER 9BDATE CHARACTER 9ADDRESS CHARACTER 30
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 17
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
SEX CHARACTER 1SALARY CHARACTER 10
KEY = SSN CHARACTER 10ORDER BY LNAME, FNAME
RECORDNAME = DEPARTMENTTYPE = ROOT OF HIERARCHY1DATAITEMS =
DNAME CHARACTER 15DNUMBER INTEGER
KEY = DNAMEKEY = DNUMBERORDER BY DNAME
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 18
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
RECORDNAME = DLOCATIONPARENT = DEPARTMENTCHILD NUMBER = 1DATA ITEMS =
LOCATION CHARACTER 15
RECORDNAME = DMANAGERPARENT = DEPARTMENTCHILD NUMBER = 3DATA ITEMS =
MGRSTARTDATE CHARACTER 9MPTR POINTER WITH VIRTUAL PARENT = EMPLOYEE
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 19
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
RECORDNAME = PROJECTPARENT = DEPARTMENTCHILD NUMBER = 4DATA ITEMS =
PNAME CHARACTER 15PNUMBER INTEGERPLOCATION CHARACTER 15
KEY = PNAMEKEY = PNUMBERORDER BY PNAME
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 20
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
RECORDNAME = PWORKERPARENT = PROJECTCHILD NUMBER = 1DATA ITEMS =
HOURS CHARACTER 4WPTR POINTER WITH VIRTUAL PARENT = EMLPOYEE
RECORDNAME = DEMPLOYEESPARENT = DEPARTMENTCHILD NUMBER = 2DATA ITEM =
EPTR POINTER WITH VIRTUAL PARENT = EMPLOYEE
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 21
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
RECORDNAME = DEPENDENTPARENT = EMPLOYEECHILD NUMBER = 2DATA ITEMS =
DEPNAME CHARACTER 15SEX CHARACTER 1BIRTHDATE CHARACTER 9RELATIONSHIP CHARACTER 10
ORDER BY DESC BIRTHDATE
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 22
Hierarchical DBMS
•Data Definition in the Hierarchical Model- Example
RECORDNAME = ESUPERVISEEPARENT = EMPLOYEECHILD NUMBER = 1DATA ITEMS =
DEPNAME POINTER WITH IRTUAL PARENT = EMLPOYEE
Data Definition
Jan. 2008 Yangjun Chen ACS-3902 23
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- Hierarchical data manipulation language (HDML)
•a record-at-a-time•HDML must be embedded in a host language such as COBOL, PL/1,Pascal, ...
user-work-area - programs•currency indicators- current of database: a single hierarchical schema and its current
database records- current of hierarchy for each hierarchical schema- current of record type for each record type•command classification- retrieval: GET- record update: INSERT, DELETE, REPLACE- current record: GET HOLD
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 24
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- GET
•GET FIRST <record type name> [WHERE <condition>]•GET NEXT <record type name> [WHERE <condition>]
$GET FIRST EMPLOYEE WHERE SALARY < ‘20000.00’;while DB_STATUS = 0 do
beginwriteln (P_EMPLOYEE.FNAME,
P_EMPLOYEE.LNMAE);$GET NEXT EMPLOYEE WHERE SALARY <
‘20000.00’end
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 25
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- GET
• GET (FIRST | NEXT) PATH <hierarchical path> [WHERE <condition>]
$GET FIRST PATH EMPLOYEE, DEPENDENT WHERE EMPLOYEE.FNAME=‘John’ AND
DEPENDENT.DEPNAME=‘John’;while DB_STATUS = 0 do
beginwriteln (P_EMPLOYEE.LNAME,
P_EMPLOYEE.BDATE,P_DEPENDENT.BIRTHDATE);
$GET NEXT PATH EMPLOYEE, DEPENDENTWHERE EMPLOYEE.FNAME=‘John’ AND
DEPENDENT.DEPNAME=‘John’end
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 26
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- GET
• GET NEXT <child record type name>WITHIN [VIRTUAL] PARENT [<parent record type
name] [WHERE <condition>]
$GET FIRST PATH DEPARTMENT, PROJECT WHERE DEPARTMENT.DNAME=‘Research’;
while DB_STATUS = 0 dobeginwriteln (P_PROJECT.PNAME);$GET NEXT PROJECT WITHIN PARENTend;
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 27
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- Calculating aggregate functions: COUNT, AVERAGE, ...
$GET FIRST PATH DEPARTMENT, DEMPLOYEE;while DB_STATUS = 0 do
begintotal_sal :=0; no_of_emps :=0;writeln (P_DEPARTMENT.DNAME);while DB_STATUS = 0 do
begin$GET VIRTUAL PARENT EMPLOYEE;total_sal := total_sal + conv_sal(P_EMPLOYEE.SALARY);no_of_emps := no_of_emps +1; $GET NEXT DEMPLOYEES WITHIN PARENT
DEPARTMENTend writeln (‘no of emps =’, no_of_emps, ‘avg sal of emps =’,
total_sal/no_of_emps);$GET NEXT PATH DEPARTMENT, DEMPLOYEES
end;
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 28
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- Update: INSERT, DELETE, REPLACE
P_EMPLOYEE.FNAME := ‘John’;P_EMPLOYEE.LNAME := ‘Smith’; P_EMPLOYEE.MINIT := ‘F’;P_EMPLOYEE.SSN := ‘567875432’; P_EMPLOYEE.ADDRESS := ‘40 N.W. 80TH ...’; P_EMPLOYEE.BDATE := ‘10-Jan-55’; P_EMPLOYEE.SEX := ‘M’; P_EMPLOYEE.SALARY := ‘30000.00’; $INSERT EMPLOYEE FROM P_EMPLOYEE;
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 29
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- Update: INSERT, DELETE, REPLACE
$GET HOLD FIRST EMPLOYEE WHERE SEX = ‘M’; while DB_STATUS = 0 do
beginwriteln (P_EMPLOYEE.LNAME,
P_EMPLOYEE.FNAME);$DELETE EMPLOYEE$GET HOLD NEXT EMPLOYEE WHERE SEX =
‘M’end;
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 30
Hierarchical DBMS
•Data Manipulation in the Hierarchical Model- Update: INSERT, DELETE, REPLACE
$GET FIRST PATH DEPARTMENT, DEMPLOYEEWHERE DNAME = ‘Reseach’; while DB_STATUS = 0 do
begin$GET HOLD VIRTUAL PARENT EMPLOYEE OF
DEMPLOYEESP_EMPLOYEE.SALARY := P_EMPLOYEE.SALARY * 1.1;$REPLACE EMPLOYEE FROM P_EMPLOYEE$GET NEXT DEMPLOYEES WHERE PARENT
DEPARTMENTend;
Data Manipulation
Jan. 2008 Yangjun Chen ACS-3902 31
Hierarchical DBMSParent/child relationships
departmentdname dnumber mgrname mgrstartdate
employeename ssn bdate address
projectpname pnumber plocation
Two parent/child relationships are in the above schema:
•department/employee
•department/project
Jan. 2008 Yangjun Chen ACS-3902 32
Hierarchical DBMS
departmentdname dnumber mgrname mgrstartdate
employeename ssn bdate address
projectpname pnumber plocation
Using the data we had previously seen in Ch 7, we can depict the following 3 instances of department/employee:
Research
Smith Wong Narayan English
Administration
Zelaya Wallace Jabbar
Headquarters
Borg
Parent/child instances
Jan. 2008 Yangjun Chen ACS-3902 33
Hierarchical DBMS
departmentdname dnumber mgrname mgrstartdate
employeename ssn bdate address
projectpname pnumber plocation
Using the data we had previously seen in Ch 7, we can depict the following 3 instances of department/project:
ProductX ProductY ProductZComputerization Newbenefits
ReorganizationAdministration
ResearchHeadquarters
Parent/child instances
Jan. 2008 Yangjun Chen ACS-3902 34
Hierarchical DBMS
ComputerizationNewbenefits
Reorganization
Administration
Research
Headquarters
SmithWong
NarayanEnglish
ZelayaWallace
Jabbar
Borg
In the following 3 hierarchical records are depicted. This is another way that such information is often depicted in practice.
Hierarchical records
ProductXProductY
ProductZ
Note that a child record cannot exist without its parent record - this is similar to the concepts of
•FK integrity and •weak entity
Jan. 2008 Yangjun Chen ACS-3902 35
Hierarchical DBMS
Schema name = companyrecord
name=department field dname character 15 field dnumber integer field mgrname character 30 field mgrstartdate datekey=dnumber
recordname=employeeparent=department field name character 15 field ssn character 9 field bdate date field address character 30key=ssn
recordname=projectparent=department field pname character 15 field pnumber integer field location character 15key=pnumber
Schema definition
Need:
Names of records
parent/child relationships
fields
keys
syntax will vary, but these are the types of things that must be present.
Jan. 2008 Yangjun Chen ACS-3902 36
Hierarchical DBMSData manipulation
Navigational - not set-oriented - you retrieve one record at a time
Retrieval
GU, Get unique
GN, Get next
GNP, Get next within parent
Updating
ISRT, Insert
DLET, Delete
REPL, Replace
retrieve a specific record
using your current position, get the next record in the database
using your current position, get the next child record for that parent
GU
, GN
, GN
P, ISR
T, D
LE
T, R
EP
L are
IMS com
mand nam
es
Jan. 2008 Yangjun Chen ACS-3902 37
Hierarchical DBMS
ProductXProductY
ProductZ
ComputerizationNewbenefits
Reorganization
Administration
ResearchHeadquarters
SmithWong
NarayanEnglish
ZelayaWallace
Jabbar
Borg
Consider the database
Navigating through the database
GU Department (dname=headquarters)Loop
GNPexit when status code = ????
End Loop
Program would retrieve the Department record and all of its dependents