Download presentation
Presentation is loading. Please wait.
Published byGalilea Proudfoot Modified over 9 years ago
1
Jan. 2012 Yangjun Chen ACS-3902 1 Hierarchical DBMSOutline Hierarchical Database Management Systems Appendix D – 3 rd ed. (Appendix E – 4 th ed. Appendix D – 5 th and 6 th ed.) 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
2
Jan. 2012 Yangjun Chen ACS-3902 2 Hierarchical DBMS department dnamednumbermgrnamemgrstartdate employee namessnbdateaddress project pnamepnumberplocation 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 between two record types. A hierarchical database schema consists of a number of hierarchical schemas. Hierarchical Schema PCR
3
Jan. 2012 Yangjun Chen ACS-3902 3 Hierarchical DBMS PCR occurrence -Each PRC occurrence relates a record of a type (e.g., a department) to some records of another type (e.g., employee). Hierarchical Schema PCR type:PCR occurrences: research WongSmithNarayan administration ZelayaWallaceJabbar research Product2Product1 Product3 administration Computerization... Department Employee Department Project
4
Jan. 2012 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 in exactly 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 PCR is called a leaf of the hierarchical schema. 5.If a record type participate as parent in more than one PCR type, then its child record types are ordered. The order is displayed, by convention, from left to right in a hierarchical diagram. Hierarchical Schema
5
Jan. 2012 Yangjun Chen ACS-3902 5 Hierarchical DBMS Hierarchical occurrence Each hierarchical occurrence, called an occurrence tree, is a tree structure whose root is a single record from some record type. Each subtree of the root is again a hierarchical occurrence. -type indicator Hiearchical Schema department dnamednumbermgrnamemgrstartdate employee namessnbdateaddress project pnamepnumberplocation D E P T SW dependent supervisee worker
6
Jan. 2012 Yangjun Chen ACS-3902 6 Hierarchical DBMS -hierarchical occurrence Hiearchical Schema Level 1: D Administration Level 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
7
Jan. 2012 Yangjun Chen ACS-3902 7 Hierarchical DBMS -linearized form of a hierarchical occurrence procedure Pre_order_traversal (root_record) begin output(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 Dadministration EZelaya EWallace TAbner SZelaya SJabbar EJabbar Pcomputerization WWong WZelaya Pnew-benefit WJabbar WZelaya
8
Jan. 2012 Yangjun Chen ACS-3902 8 Hierarchical DBMS Virtual Parent-child Relationships -Problems with hierarchical model 1.M:N relationship causes redundancy 2.The case where a record type participates as child in more than one PCR type causes redundancy 3.N-ary relationships with more than two participating record type can not be modelled -Method dealing with the three problems: virtual record type virtual PCR relationship Virtual PCR
9
Jan. 2012 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 that each 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 “virtual parent-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 ProjectEmployee Epointer P Y E EmployeeProject Ppointer E R P VC VP
10
Jan. 2012 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 be included in the virtual records since each pointer to an employee record may have a different value. Such data are called intersection data. -VPCR The relationship between a virtual child and the corresponding virtual parent is called a Virtual Parent-Child-Relationship. Virtual PCR
11
Jan. 2012 Yangjun Chen ACS-3902 11 Hierarchical DBMS Virtual Parent-child Relationships -Example: The relationship: Virtual PCR Project A B C D Employees working on the project E1, E3, E5 E2, E4, E6 E1, E4 E2, E3, E4, E5 can be stored as follows:
12
Jan. 2012 Yangjun Chen ACS-3902 12 Hierarchical DBMS Virtual Parent-child Relationships -Example: Virtual PCR A E1 E2 E3 E4 E5 E6 Ep1, 10Ep2, 8Ep3, 5 B Ep4, 20Ep5, 8Ep6, 30 C Ep7, 6Ep8, 9 D Ep10, 3Ep11, 7Ep12, 25 Ep9, 20
13
Jan. 2012 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 n n n n m 1 1 1 Works on Virtual PCR
14
Jan. 2012 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 Demployee EPTR Dmanager MPTR Pworker Hours WPTR Employee Ename Minit …... Esupervisee SPTR Dependent DEPnameMinit... DE L P Y M W S T StartDate
15
Jan. 2012 Yangjun Chen ACS-3902 15 Hierarchical DBMS Data Definition in the Hierarchical Model -Hierarchical data definition language (HDDL) record type data item of a record type key clause parent virtual record type virtual 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
16
Jan. 2012 Yangjun Chen ACS-3902 16 Hierarchical DBMS Data Definition in the Hierarchical Model -Example SCHEMA NAME = COMPANY HIERARCHIES = HIERARCHY1, HIERARCHY2 RECORD NAME = EMPLOYEE TYPE = ROOT OF HIERARCHY2 DATA ITEMS = FNAMECHARACTER 15 MINITCHARACTER 1 LNAME CHARACTER 15 SSNCHARACTER 9 BDATECHARACTER 9 ADDRESSCHARACTER 30 Data Definition
17
Jan. 2012 Yangjun Chen ACS-3902 17 Hierarchical DBMS Data Definition in the Hierarchical Model -Example SEXCHARACTER 1 SALARYCHARACTER 10 KEY = SSNCHARACTER 10 ORDER BY LNAME, FNAME RECORD NAME = DEPARTMENT TYPE = ROOT OF HIERARCHY1 DATAITEMS = DNAME CHARACTER 15 DNUMBERINTEGER KEY = DNAME KEY = DNUMBER ORDER BY DNAME Data Definition
18
Jan. 2012 Yangjun Chen ACS-3902 18 Hierarchical DBMS Data Definition in the Hierarchical Model -Example RECORD NAME = DLOCATION PARENT = DEPARTMENT CHILD NUMBER = 1 DATA ITEMS = LOCATIONCHARACTER 15 RECORD NAME = DMANAGER PARENT = DEPARTMENT CHILD NUMBER = 3 DATA ITEMS = MGRSTARTDATE CHARACTER 9 MPTRPOINTER WITH VIRTUAL PARENT = EMPLOYEE Data Definition
19
Jan. 2012 Yangjun Chen ACS-3902 19 Hierarchical DBMS Data Definition in the Hierarchical Model -Example RECORD NAME = PROJECT PARENT = DEPARTMENT CHILD NUMBER = 4 DATA ITEMS = PNAMECHARACTER 15 PNUMBERINTEGER PLOCATIONCHARACTER 15 KEY = PNAME KEY = PNUMBER ORDER BY PNAME Data Definition
20
Jan. 2012 Yangjun Chen ACS-3902 20 Hierarchical DBMS Data Definition in the Hierarchical Model -Example RECORD NAME = PWORKER PARENT = PROJECT CHILD NUMBER = 1 DATA ITEMS = HOURSCHARACTER 4 WPTRPOINTER WITH VIRTUAL PARENT = EMLPOYEE RECORD NAME = DEMPLOYEES PARENT = DEPARTMENT CHILD NUMBER = 2 DATA ITEM = EPTRPOINTER WITH VIRTUAL PARENT = EMPLOYEE Data Definition
21
Jan. 2012 Yangjun Chen ACS-3902 21 Hierarchical DBMS Data Definition in the Hierarchical Model -Example RECORD NAME = DEPENDENT PARENT = EMPLOYEE CHILD NUMBER = 2 DATA ITEMS = DEPNAMECHARACTER 15 SEXCHARACTER 1 BIRTHDATECHARACTER 9 RELATIONSHIPCHARACTER 10 ORDER BY DESC BIRTHDATE Data Definition
22
Jan. 2012 Yangjun Chen ACS-3902 22 Hierarchical DBMS Data Definition in the Hierarchical Model -Example RECORD NAME = ESUPERVISEE PARENT = EMPLOYEE CHILD NUMBER = 1 DATA ITEMS = DEPNAMEPOINTER WITH IRTUAL PARENT = EMLPOYEE Data Definition
23
Jan. 2012 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
24
Jan. 2012 Yangjun Chen ACS-3902 24 Hierarchical DBMS Data Manipulation in the Hierarchical Model -GET GET FIRST [WHERE ] GET NEXT [WHERE ] $GET FIRST EMPLOYEE WHERE SALARY < ‘20000.00’; while DB_STATUS = 0 do begin writeln (P_EMPLOYEE.FNAME, P_EMPLOYEE.LNMAE); $GET NEXT EMPLOYEE WHERE SALARY < ‘20000.00’ end Data Manipulation
25
Jan. 2012 Yangjun Chen ACS-3902 25 Hierarchical DBMS Data Manipulation in the Hierarchical Model -GET GET (FIRST | NEXT) PATH [WHERE ] $GET FIRST PATH EMPLOYEE, DEPENDENT WHERE EMPLOYEE.FNAME=‘John’ AND DEPENDENT.DEPNAME=‘John’; while DB_STATUS = 0 do begin writeln (P_EMPLOYEE.LNAME, P_EMPLOYEE.BDATE, P_DEPENDENT.BIRTHDATE); $GET NEXT PATH EMPLOYEE, DEPENDENT WHERE EMPLOYEE.FNAME=‘John’ AND DEPENDENT.DEPNAME=‘John’ end Data Manipulation
26
Jan. 2012 Yangjun Chen ACS-3902 26 Hierarchical DBMS Data Manipulation in the Hierarchical Model -GET GET NEXT WITHIN [VIRTUAL] PARENT [<parent record type name] [WHERE ] $GET FIRST PATH DEPARTMENT, PROJECT WHERE DEPARTMENT.DNAME=‘Research’; while DB_STATUS = 0 do begin writeln (P_PROJECT.PNAME); $GET NEXT PROJECT WITHIN PARENT end; Data Manipulation
27
Jan. 2012 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 begin total_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 DEPARTMENT end writeln (‘no of emps =’, no_of_emps, ‘avg sal of emps =’, total_sal/no_of_emps); $GET NEXT PATH DEPARTMENT, DEMPLOYEES end; Data Manipulation
28
Jan. 2012 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
29
Jan. 2012 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 begin writeln (P_EMPLOYEE.LNAME, P_EMPLOYEE.FNAME); $DELETE EMPLOYEE $GET HOLD NEXT EMPLOYEE WHERE SEX = ‘M’ end; Data Manipulation
30
Jan. 2012 Yangjun Chen ACS-3902 30 Hierarchical DBMS Data Manipulation in the Hierarchical Model -Update: INSERT, DELETE, REPLACE $GET FIRST PATH DEPARTMENT, DEMPLOYEE WHERE DNAME = ‘Reseach’; while DB_STATUS = 0 do begin $GET HOLD VIRTUAL PARENT EMPLOYEE OF DEMPLOYEES P_EMPLOYEE.SALARY := P_EMPLOYEE.SALARY * 1.1; $REPLACE EMPLOYEE FROM P_EMPLOYEE $GET NEXT DEMPLOYEES WHERE PARENT DEPARTMENT end; Data Manipulation
31
Jan. 2012 Yangjun Chen ACS-3902 31 Hierarchical DBMSParent/child relationships department dnamednumbermgrnamemgrstartdate employee namessnbdateaddress project pnamepnumberplocation Two parent/child relationships are in the above schema: department/employee department/project
32
Jan. 2012 Yangjun Chen ACS-3902 32 Hierarchical DBMS department dnamednumbermgrnamemgrstartdate employee namessnbdateaddress project pnamepnumberplocation Using the data we had previously seen in Ch 7, we can depict the following 3 instances of department/employee: Research SmithWongNarayanEnglish Administration ZelayaWallaceJabbar Headquarters Borg Parent/child instances
33
Jan. 2012 Yangjun Chen ACS-3902 33 Hierarchical DBMS department dnamednumbermgrnamemgrstartdate employee namessnbdateaddress project pnamepnumberplocation Using the data we had previously seen in Ch 7, we can depict the following 3 instances of department/project: ProductXProductYProductZ ComputerizationNewbenefits Reorganization Administration Research Headquarters Parent/child instances
34
Jan. 2012 Yangjun Chen ACS-3902 34 Hierarchical DBMS Computerization Newbenefits Reorganization Administration Research Headquarters Smith Wong Narayan English Zelaya Wallace Jabbar Borg In the following 3 hierarchical records are depicted. This is another way that such information is often depicted in practice. Hierarchical records ProductX ProductY ProductZ Note that a child record cannot exist without its parent record - this is similar to the concepts of FK integrity and weak entity
35
Jan. 2012 Yangjun Chen ACS-3902 35 Hierarchical DBMS Schema name = company record name=department fielddname character 15 field dnumber integer field mgrnamecharacter 30 field mgrstartdatedate key=dnumber record name=employee parent=department field namecharacter 15 field ssncharacter 9 field bdatedate field addresscharacter 30 key=ssn record name=project parent=department field pnamecharacter 15 field pnumberinteger field locationcharacter 15 key=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.
36
Jan. 2012 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, GNP, ISRT, DLET, REPL are IMS command names
37
Jan. 2012 Yangjun Chen ACS-3902 37 Hierarchical DBMS ProductX ProductY ProductZ Computerization Newbenefits Reorganization Administration Research Headquarters Smith Wong Narayan English Zelaya Wallace Jabbar Borg Consider the database Navigating through the database GU Department (dname=headquarters) Loop GNP exit when status code = ???? End Loop Program would retrieve the Department record and all of its dependents
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.