460 likes | 571 Views
THE NETWORK DATA MODEL SECTION 8. An early DBMS. Background. Networks are a natural way of representing relationships among objects. The network data model represents data in network structures of record types connected in one-to-one or one-to-many relationships.
E N D
THE NETWORK DATA MODELSECTION 8 An early DBMS
Background • Networks are a natural way of representing relationships among objects • The network data model represents data in network structures of record types connected in one-to-one or one-to-many relationships
Conference on Data Systems Language • Early 1960s • American Standards Institute (ANSI) – 1971 • IDS and IDMS
Concepts • Schema • Subschema • Physical details
Records and Sets • Record type • Set • Owner record type • Member record type
CUSTOMER SALESPERSON OWNER OWNER CUSTPO SET SALESPO SET PURCHASE-ORDER OWNER MEMBER One-to-many relationship One-to-one relationship POITEM SET LINE-ITEMS MEMBER A Bachman Diagram A Data Structure Diagram
CUSTOMER SALESPERSON Smith Jones Bean Darwin Wallace PO #1 PO #2 PO #3 PO #4 Pens Pencils Erasers Envelopes Instance or Occurrence An Example of a Network Data Structure
Types of Networks • Simple networks • Complex networks • Link record type
STUDENT STUDENT TAKING CLASS SET CLASS STUDENT- ID CLASS-ID SC ENROLLED SET CLASS Thus a complex network An Example of a Link Record
Peter Black Sue White Judy Dench PB A461 PB B304 PB E230 SW A461 SW E230 JD A461 Accounting 461 Botany 304 English 230 Expanded Example Converts a complex network into a simple network
CUST-ID NAME ADDRESS ACCT # BALANCE HAS- ACCOUNT CUSTOMER ACCOUNT 1 N CUST-ID NAME ADDRESS ACCT # BALANCE CUSTOMER ACCOUNT CUSTOMER/ACCOUNT SET The Model’s Relationship to Conceptual Modeling Semantics • An example of a conceptual model?
RULE 1 • For each entity of set E in a conceptual schema, create a record type R in the network data structure. All attributes of E are represented as fields in R
Representing One-to-Many Relationships CUSTOMER ACCOUNT CUSTOMER ACCOUNT RULE 2 For one-to-many relationships, the record type on the “one” side of the relationship becomes the owner, the record type on the “many” side becomes the member record type. If the relationship is strictly one-to-one, then the owner and member record types are chosen arbitrarily.
Transforming n-ary Relationships SOLD PRODUCT COUNTRY N M M DATE • An example could be a three-way relationship
Must create a link record PRODUCT DATE COUNTRY Date/Link Set Product/Link Set Country/Link Set LINK RECORD RULE 3 For each n-ary relationships, n > 2, create a linking record L, and make it the member record type in n set types. Designate the owner of each set type as the record type on the “one” side of the resulting on-to-many relationship.
Nov. 2, 1999 Dec. 5, 1999 Jan. 13 2000 Jan. 15, 2000 DATES • The Database from the above example LINK 1 PRODUCTS COUNTRIES Widget Australia LINK 2 Clamp Canada LINK 3 Gadget USA LINK 4
Transforming Many-To-Many Relationships MANUFACTURER PRODUCT RULE 4 • For each may-to-many relationship between entity sets E1 and E2 create a link record type L and make it the member record type in two set types, of which the set type owners are the record types corresponding to E1 and E2. • An manufacturer may produce many products, and any one of these products can be made by several manufacturers
LREC 1 MANUFACTURER PRODUCT Ron Smith Gamma, Inc Bean Mfg. 450 Maple St. 68 Main St.. 26 Harris Ave. 115 116 120 Clamp Gadget Widget 2 3 MANUFACTURER PRODUCT Manufacturer/LRec Set Product/LRec Set 4 LREC
Data Definition Language • What is the DDL? • Use the DDL to define the database schema • The following procedure should be used.
Procedure • Create the conceptual data model • Map the conceptual data model to network data structure diagrams • Use the DDL to implement the schema
A schema is made up of: • Schema section • Record sections • Set sections
Create the conceptual model HAS- INVOICE CUSTOMER INVOICE 1 M 1 CONTAINS M LINE-ITEM
Map to a network structure CUSTINV CUSTOMER INVOICE INVITEM LINE-ITEM
Implement the schema • SCHEMA NAME IS ACCOUNTSREC • RECORD NAME IS CUSTOMER • CUST-ID TYPE IS NUMERIC INTEGER • NAME TYPE IS CHARACTER 15 • ADDRESS TYPE IS CHARACTER 20 • ACCOUNT-BALANCE TYPE IS NUMERIC (5,2) • RECORD NAME IS INVOICE • INVONO TYPE IS NUMERIC INTEGER • DATE TYPE IS CHARACTER 9 • AMOUNT TYPE IS NUMERIC (5,2) • STATUS TYPE IS CHARACTER 2 • RECORD NAME IS LINE-ITEM • STOCKNO TYPE IS NUMERIC INTEGER • DESCRIPTION TYPE IS CHARACTER 20 • PRICE TYPE IS NUMERIC (4,2) • CUSTINV • OWNER IS CUSTOMER • MEMBER IS INVOICE • INVITEM • OWNER IS INVOICE • MEMBER IS LINE-ITEM
From Schema to Subschema • Title division • Mapping division • Structure division • Subschema record section • Subschema set section
Subschema Example • SS INVSTATUS WITHIN ACCOUNTSREC. • MAPPING DIVISION. • ALIAS SECTION. • AD RECORD CUSTOMER IS OWEDBY. • AD SET CUST-INV IS OWEDBY – INV. • STRUCTURE DIVISION. • RECORD SECTION. • 01 OWEDBY. • 05 CUST-ID. • 05 NAME. • 05 ACCOUNT-BALANCE. • 01 INVOICE ALL. • SET SECTION. • SD OWEDBY-INV
Data Manipulation Language • What is the DML? • Process records one at a time • The following procedure should be used.
Basic Commands • Navigational commands • Retrieval commands • Update commands • Records • Sets
Basic DML Commands Command Type FIND GET ERASE STORE MODIFY CONNECT DISCONNECT RECONNECT Navigation Retrieval Record Update Set Update
Some terms defined • User working area • Currency indicators • Status flags • Record templates
OWEDBY TEMPLATE 14 16 14 10 Bean Smith Bean Black 75 100 150 150 205 205 213 210 06-29-99 05-31-99 06-20-90 05-31-99 55 42 25 25 01 01 01 02 INVOICE TEMPLATE CURRENCY POINTERS OWEDBY INSTANCES OWEDBY INVOICE INVOICE INSTANCES OWEDBY- INVOICE RUN-UNIT User Working Area in Primary Memory Relationship of User Working Area to Database Instances
Retrieval and Update A Simple Record Retrieval MOVE 105 TO CUST-ID IN CUSTOMER FIND ANY CUSTOMER USING CUST-ID GET CUSTOMER • FIND Command • GET Command
Retrieval of all Records with a Particular Characteristic MOVE 0 TO ACCOUNT-BALANCE IN CUSTOMER FIND ANY CUSTOMER USING ACCOUNT-BALANCE DOWHILE DB-STATUS = 0 GET CUSTOMER (process customer record) FIND DUPLICATE CUSTOMER USING ACCOUNT-BALANCE END-DO
Deleting Records MOVE 0 TO ACCOUNT-BALANCE IN CUSTOMER FIND FOR UPDATE ANY CUSTOMER USING ACCOUNT-BALANCE DOWHILE DB-STATUS = 0 ERASE CUSTOMER FIND FOE UPDATE DUPLICATE CUSTOMER USING ACCOUNT-BALANCE END-DO • ERASE Command
Modifying Record Contents MOVE 502 TO CUST-ID IN CUSTOMER FIND FOR UPDATE ANY CUSTOMER USING CUST-ID GET CUSTOMER IF DB-STATUS = 0 THEN MOVE “455 Cherry Lane, Hamilton, Ontario” TO ADDRESS IN CUSTOMER MODIFY CUSTOMER ELSE (perform error routine) END-IF • MODIFY Command
Adding New Records MOVE 503 TO CUST-ID IN CUSTOMER MOVE “James W. Smith” TO NAME IN CUSTOMER MOVE “201 Scenic Drive, Hamilton,Ontario” TO ADDRESS IN CUSTOMER MOVE 500.00 TO ACCOUNT-BALANCE IN CUSTOMER STORE CUSTOMER • STORE Command
Set Operations Placing a Record in a Set MOVE 231 TO INVNO IN INVOICE MOVE “7/7/99” TO DATE IN INVOICE MOVE 100.00 TO INVOICE-AMOUNT IN INVOICE STORE INVOICE MOVE 431 TO CUST-ID IN CUSTOMER FIND ANY CUSTOMER USING CUST-ID CONNECT INVOICE TO CUSTOMER • CONNECT Command
Removing a Record from a Set MOVE 254 TO INVNO OF INVOICE FIND ANY INVOICE USING INVNO DISCONNECT INVOICE FROM CUSTINV • DISCONNECT Command
Changing Set Membership MOVE 510 TO INVNO OF INVOICE FIND ANY INVOICE USING INVNO MOVE 431 TO CUST-ID IN CUSTOMER FIND ANY CUSTOMER USING CUST-ID RECONNECT INVOICE IN CUSTINV • RECONNECT Command
Set Membership Classification • Set insertion class • Defined by the statement: • INSERTION IS <insert mode> • Manual insertion or Automatic insertion
Subschema Fragment SET NAME IS CUSTINV. OWNER IS CUSTOMER MEMBER IS INVOICE INSERTION IS MANUAL RETENTION IS OPTIONAL • Manual Insertion Mode • Must be placed by using CONNECT • CONNECT <record type> TO <set type>
Placing a Record in a Set MOVE 231 TO INVNO IN INVOICE MOVE “7/7/99” TO DATE IN INVOICE MOVE 100.00 TO INVOICE-AMOUNT IN INVOICE STORE INVOICE MOVE 431 TO CUST-ID IN CUSTOMER FIND ANY CUSTOMER USING CUST-ID CONNECT INVOICE TO CUSTOMER
Placing a Record in a Set MOVE 431 TO CUST-ID IN CUSTOMER FIND ANY CUSTOMER USING CUST-ID MOVE 231 TO INVNO IN INVOICE MOVE “7/7/99” TO DATE IN INVOICE MOVE 100.00 TO INVOICE-AMOUNT IN INVOICE STORE INVOICE • Automatic Insertion Mode • Must be placed by using STORE • STORE <record type>
Set Retention • Retention options are: • Fixed • Mandatory • Optional
Subschema Fragment CUSTINV. OWNER IS CUSTOMER MEMBER IS INVOICE INSERTION IS MANUAL RETENTION IS OPTIONAL INVITEM OWNER IS INVOICE MEMBER IS LINE-ITEM INSERTION IS MANUAL RETENTION IS OPTIONAL
Implementation • Large size • Well-defined repetitive queries • Well-defined transactions • Well-defined applications