DATA MODELS

advertisement
DATA MODELS
Here we have the following Models:
Record-based Logical Models
Object-based Logical Models
Hybrid-based Logical Models
Physical Data Models
RECORD-BASED Models:
Hierarchical Model - based on trees.
Network Model - based on graphs
Relational Model - based on tables and relationships, E-R model, semantic model.
OBJECT-BASED Models:
E-R model
O-O model
Binary model
Semantic model
Infological model
Functional data model
And others.
HYBRID_BASED LOGICAL Models:
A combination of the above
PHYSICAL DATA Model
Unifying Model
Frame Memory,
Etc.
NETWORK and HIERARCHICAL
Data Base Management Systems
For example:
1. branch, customer and account records
2. a pointer to the last record above
3. one status variable
Commands:
get
•
locate a record in the DB and set the currency pointer to it.
•
copy that record from the database to the appropriate area template
•
this get must specify which tree in the forest DB.
a) get first <record type> where <condition>
b) get next <record type> where <condition>
c) get next within parent where <condition>
Examples:
1. Select CB.
get first unique customer
where customer.name = "CB";
print (customer.address);
2. Print an account belonging to CB with balance greater than $10,000 (if one
exists)
get first account
where customer. name = "CB" and account.balance > $10000;
if status = 0 then print (account.number);
3. Within a data base tree print the account number of all the accounts on the
balance greater than $500.
get first unique account
where account. balance > $500;
while status = 0 loop begin
print (account.number);
get next account where balance> $500
end.
In system R2000:
list customer. name, customer.city
while customer has balance > $5000
4. Locate in a particular sub-tree (within parent). Print the total balance of all
accounts belonging to CB.
sum = 0;
get first customer
where customer. name = "CB";
get next within parent account;
while status = 0 loop
begin
sum = sum + account.balance;
get next within parent account;
end;
print(sum);
Updating:
Insert, Replace, Delete
5. To add new customer “Bugs” to Wonderland branch
customer.name = "Bugs";
customer.street = "Tweety Road";
customer.city = "Disneyland";
insert customer
where branch.name = "Wonderland";
(Note: it will not have an account number!)
6. To create a new account 655 for customer
account. number: = 655;
account. balance: = 100;
insert account
where customer. name = "Bugs”;
7. To change customer city of Bugs.
get hold first customer
where customer. name: = "Bugs”
customer. city: = "Warner Brothers";
replace;
(Note: the hold that the system is aware that a modification will take place).
8. To delete account 655. (1 record)
get hold first account
where account. number = 655;
delete;
9. To delete entire sub-tree rooted by that record. Delete customer CB and all his
accounts.
get hold first customer
where customer. name = "CB";
delete;
The PARADIGM from CPS510
Let us go back and examine our example of S, P and SP. The data structure diagram
(Bachman) of an n:m relationship between salespersons S and products P is represented
as 1:n relationships between salespersons and products and a relationship SP.
S
P
SP relationship
Examples
1. For each salesperson, find the product numbers, he/she supplies.
input the salesperson's identification to the field SNR in the salesperson's record.
more-SP-records= "yes"
find any S using SNR in S
find first SP within S-SP
loop until more-SP-records = "no"
get SP
keep the value of the field PNR in SP-record so that it can later
be sent to the terminal-user
find next SP within S-SP
end loop
free all
send the retained PNR numbers to user terminal.
Note:
using uses the record type.
get the record goes to user-area -> buffer can be referred to by field name
within the record.
free causes the current records of the program to be released so they can
be used by other programs. i.e. read or updated.
2. Searching for records with a particular value in a given field
read the salesperson's name into the field SNAME in S
move-salesman = "yes"
find any S using SNAME in S
until move-salesman = "no" loop
get S
keep SNR and city to be displayed later
find duplicate S using SNAME in S
end loop.
send the retained SNRs and cities to the terminal.
The aim is to find all salespersons with a particular name. It is assumed in the program
the SNAME is defined as a key field in the conceptual schema; but has to be non-unique
key; duplicates not allowed is not an option that we can take in the definition of the key
field.
Other DML Commands
The find command locates a record and the get loads it into template.
1. Simple:
customer.name: = "CB";
find any customer using name;
get customer;
print (customer.street);
customer. city: = "Wonderland";
find any customer using city;
while DB-status = 0 loop
begin
get customer
print (customer.name);
find duplicate customer using city;
end.
the duplicate locates records which reach the record-field.
2. To access records within a set.
find first <record type> within <set-type>
find next < record type> within <set-type>
find owner within <set-type>
3. Creating new records/modify/delete.
store <record type>
modify <record type>
erase [all] <record type>
4. Connect/Disconnect/Reconnect
Connect a new record type into a particular set type (occurrence of set type) we
must first store it and then connect <record type> to <set-type>
account.number: = 601;
account.balance = 0;
store account;
customer. name = "Brown";
find any customer using name;
connect account to customer-account;
Note:
•
•
disconnect: removes a record type from the set-type.
reconnect: moves a record of type <record type> from the set occurrence
to another set occurrence of type set type: reconnect <record type> to
<set type>.
Insertion/Retention/Deletion
Insertion:
manual (explicitly) by executing connect
automatic (implicitly) by executing store.
Retention:
how and when a member record can be removed (there are restrictions).
Deletion:
when the record is the owner (refers to)
Note: For the above we have: fixed, mandatory, and optional.
Set Ordering:
•
•
•
•
•
•
first: when insert - a record is inserted on top.
last: when insert - a record is inserted on bottom.
next: when insert - a record is inserted in next position from current position.
prior: when insert - a record is inserted in prior position from current position
sorted: kept sorted
system default: kept by system.
Administration Facilities
DBA Responsibilities
•
•
•
•
•
•
•
•
•
•
•
•
•
Creating the DB
Planning the logical DB and construction of the physical DB
Maintenance of the data dictionary
(description of fields, files, relationships, connections, etc)
Controlling the use of data: The DBMS may collect statistics concerning the use
of the DB, so that a check can be made (at intervals) to see whether the physical
DB is organized in an optimized way from the point of view of the current uses for
the data.
Defining security and integrity constraints: Lists attempts of unauthorized use of
data.
Preparation of recovery procedures corresponding to various error situations that
may arise
Preparation of consistency control and periodical control of the consistency of the
database
Liaising with the users - advisory to users and programmers.
Periodic checks for the reorganization of the DB
Performance tuning
Contact with software suppliers with a view to update the software, reporting
errors, etc.
Collection of information and material with a view of DB enhancement.
Backing up the DB.
Front End Subsystems and Tools
•
•
•
•
•
•
•
•
A DBMS may be supplied with a variety of tools i.e. - word processors,
spreadsheets, statistical packages, graphics, system shells, etc
Tools that a DBMS may come with are totally open according to how sophisticated
the package is in its environment. For example, upload and download tools (for
micro and mainframe application development). Design and development of
database tools.
Menus and form driven interfaces may be used for data access.
Natural language interfaces.
Report writers which facilitate automatic report generation
Business graphics.
Application packages.
CASE tools.
Download