Chapter A: Network Model Basic Concepts
Chapter A: Network Model Basic Concepts
s Basic Concepts s Data-Structure Diagrams s The DBTG CODASYL Model s DBTG Data-Retrieval Facility s DBTG Update Facility s DBTG Set-Processing Facility s Mapping of Networks to Files
Basic Concepts
s Data are represented by collections of records.
5 similar to an entity in the E-R model 5 Records and their fields are represented as record type
type customer = record type account = record customer-name: string; account-number: integer; customer-street: string; balance: integer; customer-city: string; end end
5 similar to a restricted (binary) form of an E-R relationship 5 restrictions on links depend on whether the relationship is manymany, many-to-one, or one-to-one. s Relationships among data are represented by links
A.1
A.2
Data-Structure Diagrams
s Schema representing the design of a network database.
diagram.
s A data-structure diagram consists of two basic components:
A.3
A.4
General Relationships
s To represent an E-R relationship of degree 3 or higher, connect
the participating record types through a new record type that is linked directly to each of the original record types. 1. Replace entity sets account, customer, and branch with record types account, customer, and branch, respectively. 2. Create a new record type Rlink (referred to as a dummy record type). 3. Create the following many-to-one links:
5 CustRlink from Rlink record type to customer record type 5 AcctRlnk from Rlink record type to account record type 5 BrncRlnk from Rlink record type to branch record type
A.5
A.6
A.7
A.8
DBTG Sets
s The structure consisting of two record types that are linked
Repeating Groups
s Provide a mechanism for a field to have a set of values rather
has precisely one owner, and has zero or more member records.
s No member record of a set can participate in more than one
repeating-group construct.
A.9
A.10
of host language and DBTG command statements. Statements access and manipulate database items as well as locally declared variables.
s Program work-area (or user work area) a buffer storage area
A.11
A.12
DBTG Variables
s Record Templates s Currency pointers
Example Schema
A.13
A.14
branch.
s Six currency pointers
5 Three pointers for record types: one each tot he most recently
accessed customer, account, and branch record
5 Two pointers for set types: one to the most recently accessed
record in an occurrence of the set depositor, one to the most recently accessed record in an occurrence of the set accountbranch
A.15
A.16
currency pointers
s get copies of the record to which the current of run-unit points
Locates a record of type <record type> whose <record-field> value is the same as the value of <record-field> in the <record type> template in the program work area.
s Once such a record is found, the following currency pointers are
record belonging to Johnson causes the following changes to occur in the state of the program work area.
5 The current of the record type customer now points to the record of
Johnson.
5 The current of set type depositor now points to the set owned by
Johnson
Locates (according to a system-dependent ordering) the next record that matches the <record-field>
A.17
A.18
Predicates
s For queries in which a field value must be matched with a
Locates the first database record of type <record type> belonging to the current <set-type>.
s To locate the other members of a set,k we use
find next <record type> within <set-type> which finds the next element in the set <set-type>.
s find owner within <set-type>
A.19
A.20
balance greater than $10,000. count := 0; branch.branch-name := Perryridge; find any branch using branch-name; find first account within account-branch; while DB-status = 0 do begin get account if account.balance > 10000 then count := count + 1; find next account within account-branch; end print (count);
database.
s To create a new record of type <record type>
A.21
A.22
5 find that record in the database 5 get that record into memory 5 change the desired fields in the template of <record type> 5 reflect the changes to the record to which the currency point of
<record type> points by executing modify <record type>
5 make the currency pointer of that type point to the record in the
database to be deleted
and executing
erase all <record type>
5 Deletes the owner of the set, as well as all the sets members. 5 If a member of the set is an owner of another set, the members of
that second set also will be deleted.
A.23
A.24
account A-201 and its customer, but archive the record of account A-201.
s The following program removes account A-201 from the set
statement.
connect <record type> to <set-type> s Remove a record from a set by executing the disconnect
occurrence of type depositor. The account will still be accessible in the database for recordkeeping purposes. account.account-number := A-201; find for update any account using account-number. get account, find owner within depositor, disconnect account from depositor.
statement.
disconnect <record type> from <set-type>
A.25
A.26
A.27
A.28
type <set-type> can be added to a set occurrence either explicitly (manually) or implicitly (automatically).
s Specify the insert mode at set-definition time via insertion is <insert mode>
branch.
s Set insertion is manual for set type depositor and is automatic
for set type account-branch. branch.branch-name := Downtown; find any branch using branch-name; account.account-number := A-535; account.balance := 0; store account; customer.customer-name := Hayes; find any customer using customer-name; connect account to depositor;
5 manual: 5 automatic:
A.29
A.30
from a set occurrence are specified at set-definition time via retention is <retention-mode>
s <retention-mode> can take one of the three forms:
occurrence of type <set-type> depends on the specification of the set retention of <set-type>.
s optional the record will be deleted and every member of the
1. fixed a member record cannot be removed. To reconnect a record to another set, we must erase that record, recreate it, and then insert it into the new set occurrence. 2. mandatory a member record of a particular set occurrence can be reconnected to another set occurrence of only type <set-type>. 3. optional no restrictions on how and when a member record can be removed from a set occurrence.
set that it owns will be disconnected. These records, however, will be in the database.
s fixed the record and all its owned members will be deleted; a
member record cannot be removed from the set occurrence without being deleted.
s mandatory the record cannot be erased, because the
mandatory status indicates that a member record must belong to a set occurrence. The record cannot be disconnected from that set.
A.31
A.32
Set Ordering
Set ordering is specified by a programmer when the set is defined: order is <order-mode>
s first. A new record is inserted in the first position; the set is in
position just prior to X. If X is an owner type, a new record is inserted in the last position.
s system default. A new record is inserted in an arbitrary position
chronological ordering.
s next. Suppose that the currency pointer or <set-type> points to
the set will remain sorted. The sorting order is specified by a particular key value when a programmer defines the set.
s Example: Consider the set occurrence of type depositor with the
record X.
5 If X is a member type, a new record is inserted in the next position
following X.
owner-record customer Turner and member-record accounts A-305, A-402, and A-408 ordered as indicated in our example schema (page A.14).
A.33
A.34
it is associated.
s Example data-structure diagram and corresponding database. Figure missing
account number being the key; thus, the ordering must be {A-125,A-305,A-402,A-408}
Database System Concepts A.35 Silberschatz, Korth and Sudarshan Database System Concepts A.36 Silberschatz, Korth and Sudarshan
associated with an arbitrary number of records (e.g., the account record would have a pointer to the customer record for each customer who has that account).
s Direct implementation of many-to-many relationships requires
many; the number of pointers needed is reduced, and it is possible to retain fixed-length records.
A.37
A.38
by the DBTG set depositor and this corresponding sample database. set name is depositor owner is customer member is account
customer record, we need only one pointer in the account record to represent the depositor relationship.
s A customer record can be associated with many account
records.
s Rather ant using multiple pointers in the customer record, we can
use a ring structure to represent the entire occurrence of the DBTG set depositor.
s In a ring structure, the records of both the owner an member
A.39
A.40
type record contains a second pointer which points to the owner record.
A.41
A.42
placement clustered via depositor will store members of each set occurrence close to one another physically on disk, if possible, in the same block.
s Store owner and member records close to one another physically
on disk by adding the clause near owner. placement clustered via depositor near owner
A.43
A.44
Sample Database
A.45
A.46
A.47
A.48
A.49
A.50
DBTG Set
A.51
A.52
A.53
A.54
A customer Record
A.55
A.56
A.57
A.58
A.59