Μαθ. # 14 - UCY

16
∆ΙΚΤΥΩΤΟ ΜΟΝΤΕΛΟ (Network Model) Μαθ. # 14

Transcript of Μαθ. # 14 - UCY

∆ΙΚΤΥΩΤΟΜΟΝΤΕΛΟ(Network Model)

Μαθ. # 14

• Εννοιολογικά ένα E-R µοντέλο µε σχέσειςπεριορισµένες σε one-to-many– Many-to-many σχέσεις αντιπροσωπεύονται έµµεσα– One-to-one σχέσεις δεν επιβάλλονται από το σχήµααλλά από την σηµασιολογία της εφαρµογής

• Αυτός ο περιορισµός είχε τα εξής αποτελέσµατα– ∆υνατή αποτελεσµατική υλοποίηση– Μια σχετικά απλή διαδικαστική (navigational) γλώσσαεπερωτήσεων

• Πλήρες µοντέλο δεδοµένων– Γλώσσα ορισµού (data definition language – DDL)– Γλώσσα επεξεργασίας (data manipulation language –

DML)

• The network model (and the hierarchical) models are alternative record-oriented models to the relational model for implementing a database.

• The main network model standard specification is called the CODASYL (Conference on Data Systems Languages) or DBTG (Data Base Task Group) report.

• Two representational primitives:– Records: represent entities

• Records of similar structure classified into Record Types• Data items (or attributes):

– Simple attribute– Vector: is a multi-value attribute– Repeating group: is a composite attribute

• Stored data items are called actual data items• Virtual or derived data items can also be defined

– Sets: represent N:1 relationships• They are implemented using links between records.

• A set is not identical to a mathematical set.– It has one distinguished element, the owner– Member records are ordered: 1st, 2nd, …, last

• Constrains:– Insertion constrains (Store Command): where a new

record is connected?• Automatic: based on some criterion• Manual: (use connect)

– Retentions Constraint: can a record exist on its own?• Optional (Connect)• Mandatory (Reconnect)• Fixed (Cannot be Reconnected)

– Set ordering constraint• Sorted by an ordering field• System default• First or Last (chronological ordering)• Next or prior

• The schema is represented by a schema diagram or Bachman diagram which consists of the following components:– Rectangle for records– Links for sets

• Record fields are put next to the record’s rectangle

• The model used affects the schema diagram’s forms.– Hierarchical model: the schema diagram is a tree– Network model: the schema diagram is a general graph

• For the representation of non-functional (M:N) relationships, an intermediate record type is introduced and is made the member of the two sets having as owner the two original record types.

• Example

• Two set type are fixed and automatic.

• Networks Data Manipulation Language (DML)– Consists of record-at-a-time commands– They must be embedded in a general purpose programming language

(Commonly in COBOL an PL/I)• The User Work Area (UWA):

– A set of program variables declared in host program– To communicate contents of individual records between DBMS and host

program– One program variable for each record type with same format

• Currency Indicators:– Network DML Handles retrievals and updates by navigating through the

database records (one record at a time)– Currency indicators keep track of the most recently accessed records or set

occurrences– E.g., CRU keeps track of most recently accessed record by the program of

any record type• Status Indicators:

– Status indicators return to program an indication of success or failure after each DML command is executed

– We use DB STATUS=0 to indicate successfully executed command (no errors or exceptions)

• SCHEMA NAME IS COMPANY• RECORD NAME IS EMPLOYEE

– DUPLICATES ARE NOT ALLOWED FOR SSN– DUPLICATES ARE NOT ALLOWED FOR FNAME, MINIT, LNAME

• FNAME TYPE IS CHARACTER 15• MINIT TYPE IS CHARACTER 1• LNAME TYPE IS CHARACTER 15• SSN TYPE IS CHARACTER 9• BIRTHDATE TYPE IS CHARACTER 9• ADDRESS TYPE IS CHARACTER 30• SEX TYPE IS CHARACTER 15• SALARY TYPE IS CHARACTER 10• DEPTNAM TYPE IS CHARACTER 10

• RECORD NAME IS DEPARTMENT– DUPLICATES ARE NOT ALLOWED FOR NAME– DUPLICATES ARE NOT ALLOWED FOR NUMBER

• NAME TYPE IS CHARACTER 10• NUMBER TYPE IS NUMERIC INTEGER• LOCATION TYPE IS CHARACTER 15 VECTOR• MGRSTART TYPE IS CHARACTER 9

• RECORD NAME IS WORKS_ON– DUPLICATES ARE NOT ALLOWED FOR ESSN, PNUMBER

• SSN TYPE IS CHARACTER 9• PNUMBER TYPE IS NUMERIC INTEGER• HOURS TYPE IS NUMERIC (4,1)

• SET NAME IS ALLDEPTS– OWNER IS SYSTEM

• ORDER IS SORTED BY DEFINED KEYS– MEMBER IS DEPARTMENT

• KEY IS ASCENDING NAME

• SET NAME IS WORKS_FOR– OWNER IS DEPARTMENT

• ORDER IS SORTED BY DEFINED KEYS– MEMBER IS EMPLOYEE

• INSERTION IS MANUAL• INSERTION IS OPTIONAL• KEY IS ASCENDING LNAME, FNAME, MINIT• CHECK IS DEPTNAME IN EMPLOYEE = NAME IN DEPARTMENT

• SET NAME IS CONTROLS– OWNER IS DEPARTMENT

• ORDER IS SORTED BY DEFINED KEYS– MEMBER IS PROJECT

• INSERTION IS AUTOMATIC• RETENTION IS MANDATORY• KEY IS ASCENDING NAME• SET SELECTION IS BY APPLICATION

• SET NAME IS MANAGES– OWNER IS EMPLOYEE

• ORDER IS SYSTEM DEFAULT– MEMBER IS DEPARTMENT

• INSERTION IS AUTOMATIC• RETENTION IS MANDATORY• SET SELECTION IS BY APPLICATION

• SET NAME IS P_WORKSON– OWNER IS PROJECT

• ORDER IS SYSTEM DEFAULT• DUPLICATES ARE NOT ALLOWED

– MEMBER IS WORKS_ON• INSERTION IS AUTOMATIC• RETENTION IS FIXED• KEY IS ESSN• SET SELECTION IS STRUCTURAL

NUMBER IN PROJECT = PNUMBER IN WORKS_ON

• RETRIEVAL– GET: Retrieve the CRU into the corresponding UWA variable

• NAVIGATION– FIND: Reset the currency indicators; always sets the CRU; also

sets currency indicators of involved record types and set types.There are many variation of FIND.

• RECORD UPDATE– STORE: Store the new record in the database and make it the CRU– ERASE: Delete from the database the record that is the CRU– MODIFY: Modify some fields of the record that is the CRU

• SET UPDATE– CONNECT: Connect a member record (the CRU) to a set instance– DISCONNECT: Remove a member record (the CRU) from a set

instance– RECONNECT: Move a member record (the CRU) from one set

instance to another

• GET command for retrieving the CRU• FIND commands for navigation (locating records of a

record type) and setting currency indicators– FIND ANY <record type name> [USING <field list>]– FIND ANY finds first record in database of specified “record type

name” whose field values match corresponding UWA fields specified in USING clause (the search fields)

– FIND DUPLICATES <record type name> [USING <field list>]• Example: Retrieve record for John Smith and print out his

salaryEMPLOYE.FNAME:=“John”; EMPLOYE.LNAME:=“Smith”;$FIND ANY EMPLOYEE USING FNAME, LNAME;if DB_Status = 0 then

begin$GET EMPLOYEE;writeln (EMPLOYEE.SALARY)

endelse writeln (“no record found”);

• Example: Print the names of all employees who work in the Research departmentEMPLOYE.DEPTNAME:=“Research”; $FIND ANY EMPLOYEE USING DEPTNAME;while DB_Status = 0 do

begin$GET EMPLOYEE;writeln (EMPLOYEE.FNAME,“ ”, EMPLOYEE.LNAME)$FIND DUPLICATE EMPLOYEE USING DEPTNAME;

end;

• Favorable aspects of CODASYL– High level schema architecture– An expert user can write efficient code since he

knows the internal details of the DB

• Unfavorable aspects– Horrible DML – compare this with SQL or

QBE– Low level of abstraction, user knows the

physical schema– Weak security and integrity