Network and Hierarchical Data Models References: Elmasri (2nd ed.): Chap 10 Date, 5th ed.: Appendix C. Revised: 25-8-2004 Objective: Basic understanding of Network and hierarchical datamodels that were used before the advent of relational databases. Hier and Network 1 The Network Data Model (NDM) Networks are natural ways of representing relationships among objects in maths, chemistry, sociology etc. Networks can be represented by a mathematical structure called a directed graph (digraph) A digraph consists of points or nodes connected by arrows or edges. Hier and Network 2 Conference on Data Systems Languages (CODASYL), an organisation of representatives from major hardware and software vendors and users, developed and standardised COBOL language and in late 1960s set up the Database Task Group (DBTG) to develop standards for DBMS. DBTG was heavily influenced by architecture of Integrated Data Store (IDS). Fundamental definition of NDM referred to as CODASYL DBTG model. NDM nodes are data record types and edges represent one to one or one to many relationships (links) Hier and Network 3 Concepts and definitions NDM conforms to ANSI/SPARC 3-level architecture. Conceptual level (logical view of data and relationships) is called the schema. External level (users’ views) is called the subschema. Internal level (physical storage details) is implicit in the implementation. Hier and Network 4 NDM has two basic data structures: Record Types - collections of logically related data items. Sets (cosets or links) represent one to one and one to many relationships (N.B.: NOT the same as a mathematical set). Each set has one record type called the owner and the other record type called the member. Hier and Network 5 A set has a name and is constructed from owner and member record types where arrow points from owner to member. Whole data structure is constructed from these sets. Instances or occurrences are actual record values in a data structure. NDM allows only simple networks in which all relationships are one-to-one or one-to-many but many-to-many relationships can be transformed into one- to-many. Hier and Network 6 Query Language The NDM DML statements must be embedded in a host language. Operators process one record at a time. Each user or application program has a User Working Area (UWA). Records in the subschema for that user or application are stored in the UWA together with: Record templates - formats used for records that are read into the UWA. Status flags - variables used to denote the success or failure of last operation currency indicators - pointers to current record(s) Current (record) of (the) Run Unit contains the address of the most Hier and Network 7 recently accessed record occurrence no matter what type or what set it participates in (Run Unit refers to the users program). Current of Record Type, R - contains the address of the most recently accessed record occurrence of record type R Current of Set Type, S - contains the address of the most recently accessed record participating in set type S (owner or member) Retrieval and Update Navigation: FIND (a record) Retrieval: GET Update: ERASE, STORE, MODIFY Set Update: CONNECT, DISCONNECT, RECONNECT Hier and Network 8 Hier and Network Loads the record into a record template in UWA. MOVE 105 TO CUST-ID IN CUSTOMER FIND FIRST CUSTOMER USING CUST-ID GET CUSTOMER Get info of cutomer 105. Queries in COBOL 9 Hier and Network Note: On EOF, DB-STATUS != 0 MOVE 0 TO ACCOUNT-BALANCE IN CUSTOMER FIND FOR UPDATE FIRST CUSTOMER USING ACCOUNT-BALANCE WHILE DB-STATUS = 0 ERASE CUSTOMER FIND FOR UPDATE NEXT CUSTOMER USING ACCOUNT-BALANCE END WHILE Delete customer accounts with zero balance. 10 Hier and Network MOVE 231 TO INVNO IN INVOICE MOVE "7/7/94" TO DATE IN INVOICE MOVE 100.00 TO INVOICE-AMOUNT IN INVOICE STORE INVOICE MOVE 431 TO CUST-ID IN CUSTOMER FIND FIRST CUSTOMER USING CUST-ID CONNECT INVOICE TO CUSTOMER Create a new invoice for $100.00 for customer 431. 11 Hier and Network This connects customer 431 with invoice 510 and disconnects customer 425 from invoice 510. MOVE 510 TO INVNO IN INVOICE FIND FIRST INVOICE USING INVNO MOVE 431 TO CUST-ID IN CUSTOMER FIND FIRST CUSTOMER USING CUST-ID RECONNECT INVOICE IN CUST-INV Change invoice 510 from customer 425 to customer 431. 12 Hierarchical Data Model (HDM) This grew out of practice from IBM’s Information Management System (IMS) with out any standard or mathematical basis. IMS is a widely used DBMS developed to support the Apollo moon project. In some sence, HDM is a special case of NDM, and is organised using tree data structures in which a child can have only one parent. A database is represented as an ordered set of trees. Hier and Network 13 Basic Ideas There are two basic data types. Segment Types correspond to record type of NDM. PCR Types (Parent-Child Relationship Types) represent a relationship between a parent and child. There is a single segment called the root segment which does not participate as a child in any PCR type. Apart from the root segment, every segment participates as a child in exactly one PCR type. A segment can participate as a parent segment in more than one PCR type. Hier and Network 14 For any segment type A, there is a single path in the tree from the root to A. The records along this path are called ancestors of A. A is a dependent segment of all segments on that path, including the root segment. Database records (occurrences) contain actual values. Each occurrence is a distinct tree (in an ordered set of trees) containing one root segment. Hier and Network 15 IMS DML (DL/1) The data manipulation language of IMS is called Data Language 1 (DL/1). Database description (DBD) defines format, length and location of each data item and position in tree structure. System maintains a program work area for each application which contains, Segment templates - segment format. Currency pointers - for each database tree; contains the address of segment in tree most recently accessed. Status flags - indicate outcome of last db operation, e.g. successful status = 0. Hier and Network 16 Common Commands The general syntax is, Command <seg name> <qual> GET UNIQUE (GU) - retrieve first segment that satisfies condition. GET NEXT (GN) - get next segment. GET NEXT WITHIN PARENT (GNP) retrieve next segment only within current parent segment. INSERT (ISRT) - add a segment. REPLACE (REPL) - modify a value in a segment field. DELETE (DLET) - delete a segment. Hier and Network 17 Hier and Network GU DEPARTMENT EMPLOYEE (EMPNAME = ’Steve Smith’) Get employee record for Steve Smith; don’t know where he is assigned (requires sequential search of DEPARTMENT segments). GU DEPARTMENT (DEPTNAME = ’Marketing’) EMPLOYEE (EMPNAME = ’Steve Smith’) Get employee record for Steve Smith who works in Marketing. (Retrieves a dependent segment by specifying path.) Examples 18 Hier and Network Deletes linked segments as well. GHU DEPARTMENT (DEPTNAME = ’Marketing’) EMPLOYEE (EMPNAME = ’Irving Schatz’) DLET Delete Irving Schatz’s record GHU DEPARTMENT (DEPTNAME = ’Marketing’) EMPLOYEE (EMPNAME = ’Irving Schatz’) MOVE 25000 TO SALARY REPL Change Irving Schatz’s salary, in Marketing, to $25,000 19