0% found this document useful (0 votes)
20 views46 pages

DBMS 4

Uploaded by

namarahul545
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views46 pages

DBMS 4

Uploaded by

namarahul545
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

NETWORK

&
HIERARCHICAL
MODEL
UNIT-IV
NETWORK MODEL:BASIC CONCEPTS

• Data are represented by collections of records.


-- similar to an entity in the E-R model
-- Records and their fields are represented as record type
-- type customer = record type account = record type
customer-name: string; account-number: integer;
customer-street: string; balance: integer;
customer-city: string; end
end
• Relationships among data are represented by links
-- similar to a restricted (binary) form of an E-R relationship
-- restrictions on links depend on whether the relationship is many-many,
many-to-one, or one-to-one
DATA STRUCTURE DIAGRAMS

Schema representing the design of a network database.


• A data-structure diagram consists of two basic components:
o Boxes, which correspond to record types.
o Lines, which correspond to links.
• Specifies the overall logical structure of the database.

For every E-R diagram, there is a corresponding data-structure diagram

20XX PRESENTATION TITLE 3


Since a link cannot contain any data value, represent an
E-R relationship with attributes with a new record type
and links.
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.

• Replace entity sets account, customer, and branch with record types
account, customer, and branch, respectively.
• Create a new record type Rlink (referred to as a dummy record type).
• Create the following many-to-one links:
o CustRlink from Rlink record type to customer record type
o AcctRlnk from Rlink record type to account record type
o BrncRlnk from Rlink record type to branch record type
DBTG CODASYL MODEL
o All links are treated as many-to-one relationships.
o To model many-to-many relationships, a record type is defined to
represent the relationship and two links are used.

20XX PRESENTATION TITLE 8


DBTG SET

• The structure consisting of two record types that are linked together is referred to
in the DBTG model as a DBTG set.
• In each DBTG set, one record type is designated as the owner, and the other is
designated as the member, of the set.
• Each DBTG set can have any number of set occurrences (actual instances of
linked records).
• No member record of a set can participate in more than one occurrence of the set
at any point.
• A member record can participate simultaneously in several set occurrences of
different DBTG sets.

20XX PRESENTATION TITLE 9


Repeating Groups
• Provide a mechanism for a field to have a set of values rather than a single
value.
• Alternative representation of weak entities from the E-R model
• Example: Two sets. z customer (customer-name) z customer-address (customer-
street, customer-city)
• With the repeating-group construct, the data-structure diagram consists of the
single record type customer.
DBTG RETRIEVAL FACILITY

The DBTG data manipulation language consists of a number of commands that are
embedded in a host language.
• Run unit — system application program consisting of a sequence of host
language and DBTG command statements. Statements access and
manipulate database items as well as locally declared variables.
• Program work-area (or user work area) — a buffer storage area the system
maintains for each application program

20XX PRESENTATION TITLE 12


Program Work
***In DBTG model find command is used to find any record from the
database and sets concurrency pointers.
branch.branch-name := “Perryridge”;
find any branch using branch-name;
find first account within account-branch
***In DBTG model get command copies of the record to which the current of
run-unit points from the database to the appropriate program work area template.

get account
if account.balance > 10000 then count := count + 1;
find next account within account-branch
DBTG UPDATE FACILITY
DBTG mechanisms are available to update information in the database.
• To create a new record of type
-- insert the appropriate values in the corresponding template
--add this new record to the database by executing store
-- Can create and add new records only one at a time

• To modify an existing record of type


-- find that record in the database
-- get that record into memory
-- change the desired fields in the template of <record-type>
-- reflect the changes to the record to which the currency point of points by
executing
Modify <record-type>
20XX PRESENTATION TITLE 16
• To delete an existing record of type
-- make the currency pointer of that type point to the record in the database
to be deleted
--delete that record by
executing erase<record-type>

• Delete an entire set occurrence by finding the owner of the set and executing
--erase all<record-type>
--Deletes the owner of the set, as well as all the set’s members.
-- If a member of the set is an owner of another set, the members of that
second set also will be deleted.
--erase all is recursive
MAPPING FILES TO NETWORK

• We implement links by adding pointer fields to records that are associated via a
link
--Each record must have one pointer field for each link with which it is
associated.
--Example data-structure diagram and corresponding database.

• Diagram showing the sample instance with pointer fields to represent the links.
Each link is replaced by two pointer

20XX PRESENTATION TITLE 18


HIERARCHICAL MODEL

This database model organizes data into a tree-like-structure, with a single root,
to which all the other data is linked. The hierarchy starts from the Root data, and
expands like a tree, adding child nodes to the parent nodes.

• In this model, a child node will only have a single parent node.
• This model efficiently describes many real-world relationships like index of a
book, recipes etc.
• In hierarchical model, data is organized into tree-like structure with one one-to
many relationship between two different types of data, for example, one
department can have many courses, many professors and of-course many
students.

20XX PRESENTATION TITLE 20


A hierarchical database consists of a collection of records which are connected to
one another through links.
• A record is a collection of fields, each of which contains only one data value.
• A link is an association between precisely two records
• The hierarchical model different from the network model in that the records are
organized as collections of trees rather than as arbitrary graphs.

Advantages of Hierarchical Model


• Easy to understand.
• Performance is better than relational data model.
• Many children per parent.
• Distribute data in terms of relationships.
• Improve data sharing
Tree-Structure Diagram
A tree-structure diagram is the schema for a hierarchical database. Such a
diagram consists of two basic components:-
• Boxes, which correspond to record types
• Lines, which correspond to links

***It is somehow similar to the data structure in the network model, the
difference is that network model records are organized in the graph form
whereas in the hierarchical model records are organized in tree structure.
A parent may have an arrow pointing to child ,but a child must have an
arrow pointing to its parent
• Database schema is represented as a collection of tree-structure
diagrams.
› single instance of a database tree
The root of this tree is a dummy node
› The children of that node are actual instances of the
appropriate record type
• When transforming E-R diagrams to corresponding tree-structure
diagrams, we must ensure that the resulting diagrams are in the form
of rooted trees.
• Example E-R diagram with two entity sets, customer and account,
related through a binary, one-to-many relationship depositor.
• Corresponding tree-structure diagram has
•• the record type customer with three fields: customer-name,
customer-street, and customer-city.
• the record type account with two fields: account-number and
balance
› the link depositor, with an arrow pointing to customer

• If the relationship depositor is one to one, then the link depositor has
two arrows.
• Only one-to-many and one-to-one relationships can be directly
represented in the hierarchical mode.
DATA RETRIEVAL IN HIERARCHICAL MODEL
• We present querying of hierarchical databases via a simplified version of
DL/I(data language/1), the data-manipulation language of
IMS(Information Management System by IBM.
• Example schema:
customer-account-branch
--A branch can have several customers, each of which can have several
accounts.
--An account may belong to only one customer, and a customer can
belong to only one branch.

20XX PRESENTATION TITLE 30


Program Work Area
A buffer storage area that contains these variables
a. Record templates
b. Currency pointers
c. Status flag
-> A particular program work area is associated with precisely one
application program.
• Example program work area:
• Templates for three record types:customer, account, and branch.
• Currency pointer to the most recently accessed record of branch,
customer, or account type.
• One status variable.
• Data items are retrieved through the get command
• locates a record in the database and sets the currency pointer
to point to it
• copies that record from the database to the appropriate
program work-area template
• To scan all records in a consistent manner, we must impose an
ordering on the records.
• Preorder search starts at the root, and then searches the subtrees of
the root from left to right, recursively.
• Starts at the root, visits the leftmost child, visits its leftmost child, and
so on, until a leaf (childless) node is reached.
• Move back to the parent of the leaf and visit the leftmost unvisited
Child.
**Proceed in this manner until the entire three is visited.
• Print the address of customer Fleming:
get first customer
where customer.customer-name -— “Fleming',
print (customer.customer-address),
• Print an account belonging to Fleming that has a balance greater than
$10,000.
get first account
where customer.customer-name -— “Fleming', and
account.balance > 10000;
if DB-status —— 0 then print (account.account-number);
DATA UPDATE IN HIERARCHICAL MODEL

• Various mechanisms are available for updating information in the


database.

• Creation and deletion of records (via the insert and delete


operations).

• Modification (via the replace operation) of the content of existing


records.

20XX PRESENTATION TITLE 35


Creation of records
• To insert <record type> into the database, first set the appropriate values in
the corresponding <record type> work-area template. Then execute
insert <record type>
where <condition>
• If the where clause is included, the system searches the database three (in
preorder) for a record that satisfies the <condition> in the where clause.
• Once such a record say, X is found, the newly created record is
inserted in the tree as the leftmost child of X.
• If where is omitted, the record is inserted in the first position (in preorder) in
the tree where <record type> can be inserted in accordance with the
specified schema.
• Add a new customer, Jackson, to the Seashore branch:
customer.customer-name :—— “Jackson”;
customer.customer-street :-— “Old Road', customer.customer-city’Oueens’,
insert customer
where branch.branch-name -— “Seashore',

• Create a new account numbered A-655 that belongs to customer “Jackson";


account.account-number :-— “A-655”;
account.balance := 100; insert account
where customer.customer-name -— “Jackson',
Modification of Records
• To modify an existing record of type <record type>, we must get that record
into the work-area template for <record type>, and change the desired fields in
that template.
• Reflect the changes in the database by executing
replace

• Change the street address of Boyd to Northview:


get hold first customer
where customer.customer-name =“Boyd’, ]
customer.customer-street = “Northview’“,
replace;
Deletion of Records
• To delete a record of type <record type>, set the currency pointer to
point to that record and execute delete.
• As a record modification, the get command must have the attribute hold
attached to it. Example:Delete account A-561:
get hold first account
where account.account-number -— ‘A-561";
delete;
•A delete operation deletes not only the record in question, but also the entire
subtree rooted by that record.Thus, to delete customer Boyd and all his
accounts, we write
get hold first customer
where customer.customer-name —- “Boyd”;
delete;
VIRTUAL RECORDS
• For many-to-many relationships, record replication is necessary to
preserve the tree-structure organization of the database.
--Data inconsistency may result when updating takes place
--Waste of space is unavoidable

• Virtual record contains no data value, only a logical pointer to a particular


physical record.
• When a record is to be replicated in several database trees, a single copy of that
record is kept in one of the trees and all other records are replaced with a virtual
record.

20XX PRESENTATION TITLE 40


• Eliminate data replication in the diagram; create virtual-customer and
virtual-account.
• Replace account with virtual-account in the first tree, and replace
customer with virtual-customer in the second tree.
• Add a dashed line from virtual-customer to customer, and from virtual-
account to account, to specify the association between a virtual record and its
corresponding physical record.
MAPPING HIERARCHIES TO FILES

• Implementations of hierarchical databases do not use


parent-to-child pointers, since these would require the use of variable- length
records.
• Can use leftmost-child and next-sibling pointers which allow each record
to contain exactly two pointers.
--The leftmost-child pointer points to one child.
--The next-sibling pointer points to another child of the same parent.

20XX PRESENTATION TITLE 43


• Implementation with parent-child pointers.
• Implementation with leftmost child and next-sibling pointers.
• In general, the final child of a parent has no next sibling; rather than setting the
next-sibling filed to null, place a pointer (or preorder threat that points to the
next record in preorder.
• Using preorder threads allows us to process a tree instance in preorder simply
by following pointers.

You might also like