Databases Cutajar & Cutajar
Databases
Cutajar & Cutajar
Databases 2
Conventional File Approach
Each section keeps a separate file for storing information
Example: Attendance and Results files
STUDENT ATTENDANCE INFORMATION
Surname Name ID Address Father Class ABSENT
Zammit John 217787M 7 Main Street, Zebbug Charles IT7B 23
Cutajar Mary 323187G 9 St. Martin Street, Zejtun George IT4C 1
Piscopo Natalie 787887M 9, B. Zammit Street, Attard Peter II2F 78
STUDENT RESULTS INFORMATION
Surname Name ID Address Class Subject Mark
Zammit John 217787M 7 Main Street, Zebbug IT7B English 45
Cutajar Mary 323187G 9 St. Martin Street, Zejtun IT4C Maths 90
Piscopo Natalie 787887M 9, B. Zammit Street, Attard II2F Korean 12
Duplication of data
Databases 3
Problems in Conventional File Systems
The computer-based subsystems, being self-contained, do not represent the way in which organizations really work
Systems communicate with each other outside the computer
Possibly data inconsistencies
Data duplication
Data non-shareable
Overall view of company to help decision-making process is almost next to impossible because of the large amount of work involved. Information from different departments has to be collated before appropriate statistics could be obtained - much duplication of data is likely, creating unnecessary maintenance, risk of inconsistencies and wastage of storage space.
Databases 4
Example
Consider a customer order
Customer order(input)
ORDER PROCESSING
SYSTEM
Invoice(output)
Customer (debtor)
data
SALES ACCOUNTING SYSTEM
(debtor’s control)
Statements & confirmation of payments
Required stock (lacking)
PURCHASING
SYSTEM Stock order
Databases 5
Integrated File Systems
To overcome some of the problems with conventional file systems, integrated file systems are employed. Here, the data is pooled into a set of interlocking and interdependent files, which are accessible by a number of different users (and applications).
Process
File A
File B
File C
E.g.:
Stock file
E.g.:
Order file
…
User 1
User 2
User 3
…
Databases 6
Problems with integrated file systems.
When a transaction enters the system, ALL the appropriate files are updated.
Most integrated file systems in use are usually tailor-made to meet the requirements of particular organizations.
Data duplication problem still remains
The task of maintaining the data is shared between the programs that access and maintain the data and therefore lacks proper central control.
Programs are still dependant on the nature of the data stored and vice-versa.
Databases 7
DataBase Management System
Databases represent a radically different approach to solving the problems discussed.
Definition: A DATABASE is a single organized collection of structured data stored with a minimum of duplication of data items so as to provide a consistent and controlled pool of data. This data is common to all users of the system, but is independent of the programs that use it.
(Alternative definition: A DATABASE is collection of non-redundant data shareable between different application systems)
Databases 8
DBMS
It is essentially a computerized record-keeping system.
PROCESS
USER 1
USER 2
USER 3
D
B
M
S
DATABASE
Databases 9
Database Access
Note that, the DBMS is the only medium through which any user may access the data in the database.
USER 3
USER 4
USER 5
USER 1
USER 2
DBMS
DataBase
Here it is assumed that the data is contained in a single database. In practice there is often reason for the data to be split across several distinct databases.
Databases 10
Computer System
Database management systems are available on machines ranging from small microcomputers to the largest mainframes. The facilities provided are to some extent determined by the size and power of the underlying machine.
On large machines one would usually find a multi-user system.
On small microcomputers it is more usual to have a single user database system.
Multi-User SystemSingle-User System
Databases 11
Hardware Requirements
With regards to hardware requirements, databases demand large secondary storage facilities, and other demands depending on the circumstances.
Distributed System
Direct access storage e.g. disc packs, and so on.
On-line storage i.e. computer can access a given record without human intervention
In a multi-user system, users can access the database at the same time
For distributed databases, a fast, reliable communications network would be a requirement.
Databases 12
Database Environment
In a Database Environment there are three classes of users:
Application Programmer Responsible for writing programs that use the database
End User May access database via an application program
Database Administrator (DBA)Has central responsibility of the system.
Databases 13
Application Programmer
Responsible for writing programs that use the database (by issuing appropriate requests to the DBMS)
Batch applications – on-line applications
Function of programs is to support an end user
Databases 14
End User
May access database via an application program or use the interface provided as an integral part of the system by which the user is able to issue high level commands to the DBMS.
Typical functions include:
Data Entry
Issue of Reports
Queries
Databases 15
Database Administrator (DBA)
Co-ordinates database design
Loads the database
Controls access to the database (ensures privacy and security)
Establishes backup and recovery procedures
Controls changes to the database
Selects and maintains database management software
Meets the users to resolve problems and determine changing requirements
The DBA has central responsibility of the system.
Databases 16
Advantages of Databases vs Traditional Methods
Compactness : no need for voluminous paper files
Speed : the machine can retrieve and change data much faster than any human
Less drudgery : much of the sheer tedium of maintaining files by hand is eliminated
Currency : accurate up-to-date information is available on demand at any time.
Faster and cheaper development of new applications
Databases 17
In case of a multi-user environment
The database system provides the enterprise with centralized control of its data
Redundancy can be reduced (more usually controlled rather than totally eliminated
Inconsistency can be avoided Data can be shared Standards can be enforced: to enable data interchange; standards may
include corporate, installation, industrial, national, international Security restrictions can be applied: ensuring access to database through
proper channels; provision of security checks on access Integrity can be maintained: ensuring that the data in the database is
accurate Conflicting requirements can be balanced: provide overall service that is
‘best for the enterprise’ Provision of data independence i.e. if application programs are revised,
these changes do not effect the database itself and vice-versa.
Databases 18
Disadvantages of databases vs traditional methods
High initial investment in hardware, software and training
Generality that a DBMS provides for defining and processing data
Overhead for providing security, concurrency control, recovery, and integrity functions
(additional problems may arise if the database designers and DBA do not properly design the database or if the database systems applications are not implemented properly)
Databases 19
The Database Management System
The database management system (DBMS) is a complex software system (system software), which constructs, expands and maintains the database.
Main objective of DBMS
The DBMS handles all requests from the users for access to the database hence shielding users from hardware level details.
Databases 20
Functions of a DBMS
Allocates storage to data Maintains indices so that any required data can be retrieved, allowing for
separate items of data in the base can be cross-referenced Maintains data in the database by providing facilities for adding new
records, deleting records, amending records and adding new sets of records (data files)
Provides an interface with user programs: Programmer need not be familiar with the structure of the database, and write programs in different programming languages
File processing facilities: Process a complete file (serial/sequential), process required records (selective sequential/random) and retrieve individual records
Provides security of data: Protects data against unauthorized access, corruption and providing recovery and restart facilities after a hardware or software failure
Keeps statistics of the use made of the data, allowing redundant data to be removed and Frequently used data to be kept in the most accessible form
Databases 21
Data Modeling
In designing a database for an enterprise, initially one has to identify and state what data needs to be stored – the data requirements.
Example: Stock control application-
Each stock item has a stock number, a description, price, quantity in stock, reorder level and supplier
Each item has only one supplier
From this statement of data requirements a conceptual data model is produced.
OPERATIONAL DATA = ENTITIES + RELATIONSHIPS
E.g. suppliers E.g. suppliers supplies a certain kind of part – hence link between supplier and part entities
Databases 22
The Conceptual Data Model
A conceptual data model describes how the data elements in the system are to be grouped. Three terms are used in building a picture of the data requirements. An entity is a thing of interest to an organization about which data is to
be stored. - Example: stock, supplier,
An attribute is a property or characteristic of an entity. - Example: stock item description
A relationship is a link or association between entities.- Example: link between stock items and suppliers: - one supplier may supply many stock items
This conceptual/logical model is created without any regard to what type of database system will eventually be used to implement it.Example: the entity stock and its attributes are expressed as follows:
STOCK(part_number, description, price, quantity, reorder level, supplier)
Databases 23
Types of Relationships
Each relationship has a name (e.g. supplies) and a degree, which may be any of:
one-to-one
one-to-many (or many-to-one)
many-to-many
Example :- the relationship between supplier and stock:
Name : supplies (as indicated)
Degree: one-to-many
(a supplier supplies many stock items)
Databases 24
Other Examples
E.g. 1: One-to-one: a specialist is assigned to a single ward
(Given that a specialist has one ward of patients under his care)
E.g. 2: One-to-many: a hospital ward occupied by many patients (but a patient is assigned to only one ward).
E.g. 3: Many-to-many: a student may study several courses, each course has many students enrolled on it.
Exercise: Identify the relationship between these entities:
stock item and supplier
CD and song
Borrower and book
Databases 25
Entity-Relationship Diagrams(E-R Diagrams)
An entity-relationship diagram is a diagrammatic way of representing the relationships between the entities in a database. To show the relationship between two entities, both the degree andthe name of the relationship need to be specified.
An E-R diagram illustrates the entities and their relationships for a specific system.
is occupied by
SPECIALIST WARD
WARD PATIENTS
STUDENT COURSE
studies
Databases 26
Example 1
The data requirements for a hospital in-patient system are defined as follows: A hospital is organized into a number of wards. Each ward has a ward
number and a name recorded, along with a number of beds in that ward. Each ward is staffed by nurses. Nurses have their staff number and name recorded, and are assigned to a single ward.
Each patient in the hospital has a patient identification number, and their name, address and date of birth are recorded. Each patient is under the care of a single consultant and is assigned to a single ward. Each consultant is responsible for a number of patients. Consultants have their staff number, name and specialisation recorded.
(i) State four entities for the hospital in-patient system and suggest an identifier for each of these entities.
(ii) Draw an entity-relationship diagram to show the relationship between the entities.
Databases 27
Solution 1
ENTITY NAME
Ward Ward Number
Nurse Staff Number
Patient Patient Identification Number
Consultant Staff Number
staffed by visitsholds
PATIENTWARDNURSE CONSULTANT
Databases 28
Example 2
Drawing an E-R diagram to represent this situation:
CUSTOMER ORDER
ORDER ITEM
CUSTOMER ITEM
All the relationship
pairs
is for
sends receives
ORDER
CUSTOMER
ITEM
In a mail order system, a customer may place an order for several items. Over a period of time, the same customer may place several orders.