Download The Database Concept

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft SQL Server wikipedia , lookup

Oracle Database wikipedia , lookup

IMDb wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Database wikipedia , lookup

Functional Database Model wikipedia , lookup

Relational model wikipedia , lookup

ContactPoint wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Transcript
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Unit 5.1 – The Database Concept
Candidates should be able to:
a. Describe a database as a persistent organised store of data.
b. Explain the use of data handling software to create, maintain and interrogate a database.
What is a Database?
A database is a persistent, organised store of related data.
Persistent
•
Data and structures are maintained when data handling applications are no longer running
(they are held on some form of permanent medium such as a disk or flash memory).
Organised
•
•
Data is stored in a very structured way, using tables, records and fields.
Easy for users and applications to add, delete, edit, search & manipulate data.
Related
•
•
Individual items of data have a connection of some sort.
The data in a database is not just a haphazard collection of facts
Computerised Databases are better than Manual Databases (paper) because…
• data can be accessed by multiple users at the same time
• data can be queried / interrogated and resulting answers viewed
• data can be modified and made available to all end users quickly
• fewer errors in data processing
• data can be output to suit users’ needs (e.g. graphs, reports, forms), on screen or printed
A computerised database is a collection of related data stored in one or more
computerised files in a manner that can be accessed by users or computer
programs.
Most computerised databases are operational databases, meaning that data going into the
database is used in real time to support the on-going activities of a business. A supermarket
accounting system is an example: as items are sold, the inventory database is updated and the
inventory information is made available to the sales staff.
Computers have the ability to store large amounts of data in a compact space and to process it
speedily. Organisations of all sizes use databases to store, sort, interrogate and manage their data.
1
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Hospitals
•
•
•
•
•
Details of patients, doctors and treatments
Admissions
Consultations
Staffing
Stock control
Businesses
•
•
•
Manage and monitor sales, stock and staff etc.
Analyse performance of business / employees
Monitor trends in customer purchases to identify market opportunities
Internet Search engines
•
•
Google, Bing, Yahoo, etc.
Powerful databases to collect the details of websites, search criteria etc.
Database Levels
A database can be viewed at three levels:
•
•
•
The external view
The conceptual view
The physical view
Further details can be found here:
http://www.basicsofcomputer.com/three_level_architecture_of_database_system.htm
External View:
This is what the user sees. It is a view that is designed to be useful for a particular job.
Generally there will be a user-friendly interface that will allow the end-user to interact with
the data contained within the database. The user does not need to be aware of the physical
structure of the database, or how the data is stored within it.
2
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Conceptual View:
This is concerned with how the data is organised. It has to do with the design of the tables,
the types of data stored, validation rules used and how tables are linked. This is the
equivalent of the ‘Design View’ when using MS Access.
Physical View:
•
•
This is concerned with how the data is actually stored on the storage medium.
The designers and the users of the database are not concerned with this detail. It is
looked after by the database software.
Types of Database
Databases can be constructed in various ways according to the user’s requirements.
Flat file Database
•
•
•
This is a single table such as can be set up in a spreadsheet.
Only suitable for very simple data-handling requirements, such as an address book.
As soon as requirements become more complicated, they lead to all sorts of problems.
3
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Relational Database
In some situations, items in a database relate to each other like the branches on a tree.
Then a hierarchical database might be suitable.
Database Software
It is important not to confuse a database with the software that handles it. Software is
needed to make use of the data in the database. The software may be specially written in a
programming language like C++ or it might be part of a Database Management System
(DBMS). You do not normally buy database software applications off the shelf because each
business is different and therefore has specific needs regarding its data.
The DBMS will enable a user to perform specific actions such as:
•
•
•
•
•
•
•
•
Creating an empty database
Deleting an entire database
Creating and deleting tables
Inserting new records into tables
Updating and deleting records
Being able to extract data sets
Being able to produce reports that summarise the data
Being able to process the data to create new data
There are many database management systems that are either commercial products or free
open source applications. Examples include:
MySQL
Access
Base
Oracle
A very popular, free open source system, widely used on web sites
Included in some versions of the Microsoft Office suite
Part of the free Open Office suite
A multi-user enterprise level database management system. Widely used in
industry
4
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Use of Data Handling Software: Creating a Database
The Data Handling software that you will be most familiar with is probably MS Access,
although you may have experience of others! Whichever software you choose, the structure
and mechanics remain the same…
Creating the Database Structure
1. Create relevant FIELDS with appropriate data types, sizes & validation rules
e.g.
Field Name
StudentID
Surname
FirstName
DoB
...
Data Type
Integer
String
String
Date/Time
...
Validation
Required. Must be Unique
Required. Max 25 Characters
Required. Max 25 Characters
Required. < 01/01/1995
...
2. Nominate or create a KEY FIELD for each table ((StudentID)
3. Save FIELDS as a TABLE e.g. Student
4. Enter Data into database fields to form Records
e.g.
StudentID
0001
0002
0003
0004
...
Surname
Banks
Dover
Fischel
Peace
...
FirstName
Robin
Eileen
Arty
Warren
...
DoB
19/06/1991
25/06/1994
08/05/1990
17/03/1992
etc...
...
...
...
...
...
Each
h complete set of fields forms a single record with a unique entry in the KEY FIELD.
This example database FILE contain
contains just one table and is known as a flat-file database.
There are number off limitations to such databases. Relational contain multiple linked tables
and offer many advantages over flat
flat-file databases.
5
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Using Data Handling Software to Maintain a Database
Database maintenance involves the following:
•
•
•
Add / Insert new records into a database in the correct location (e.g. new student)
Delete existing data records (e.g. remove records of old students)
Update / Edit existing data items within existing data records (e.g. update exam grades)
Using Data Handling Software to Interrogate a Database
Database interrogation involves using the database management software to query (search)
the database for information.
Example Reasons to query data:
•
•
•
Identify a group of records that share a certain attribute
e.g. List all Rock music in your iTunes library
Calculate totals based on the information held in records
e.g. calculating the total value of the assets held by a company.
Update the details of a specific record or group of records
e.g. update termly levels for all students in a year group / class
The above list shows that queries are a means of producing information from data. This
information is used by the decision makers in organisations to plan strategies and tactics.
Databases usually allow users to create, save and then reuse queries.
Query Design
Specifies which records to search for and which fields to display.
Simple Query
- looks for data in one field only
(e.g. all songs in playlist by Led Zeppelin)
Complex Query - looks for data in multiple fields
(e.g. all songs in playlist by Led Zeppelin from the album Led Zeppelin II)
The example of a simple query below uses a Microsoft Access database table and a query to
find the names of all songs that are classified as “Rock” and have been played more than 10
times. This involves the following steps:
•
•
•
Adding the 'Songs' table to the query;
Selecting the fields to display;
Adding the search criteria against the correct fields (‘Genre’ and ‘Plays’)
6
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
SQL
The standard language for manipulating a database is called Structured Query Language
(SQL). Each DBMS supports a standard set of commands such as:
•
•
•
•
•
•
•
•
•
CREATE DATABSE
DROP DATABASE
CREATE TABLE
DELETE TABLE
EMPTY TABLE
INSERT {Record}
UPDATE {Record}
SELECT {Records}
DELETE {Records}
There are also SQL commands that can summarise data sets and to carry out mathematical
operations on the relevant data types. In order to carry out a task on a database an
instruction is written using one or more of the above statements. This instruction is called
an SQL query. These can be fairly simple or they can be extremely complicated.
Example of an SQL statement
SELECT * FROM MyDatabase.Names WHERE 'First_Name' = 'John'
The first keyword is 'SELECT' which means a set of records is going to be extracted from the
database. The asterisk * means 'every field in the record'.
Then comes FROM which defines which parts of the database is to be used, in this case a
single table called 'Names' from the database called 'MyDatabase'.
Then comes the very important WHERE clause. This defines a condition that causes only a
sub-set of the table(s) to be extracted. In this case the field called 'First_Name' must contain
the name 'John'.
In English, this says “Get me all the records from Names that have the first name John”.
SQL fun & games:
http://www.sqlzoo.net
7
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Data Storage
The data in a database can be physically stored in different ways, each offering particular
advantages and disadvantages.
Serial Data files
In a serial data file the each record is as large as the data to be stored and there are no
empty records. Serial data files are therefore often the most memory efficient way to store
data.
In this type of file structure the computer has to read through the data record-by-record
until it finds the record that is needs to access. This makes accessing data from a serial file
relatively slow.
If a record is deleted or edited then the complete altered file is re-written back to the
storage medium which is relatively slow and may involve writing to a temporary file until
the process is completed. The original file is then replaced by the altered temporary file.
Sequential Data Files
Basically the same as serial files except that the records are stored in order of a designated
key field. This means records can be found more quickly. Similar issues remain when new
records need to be inserted, or old records need to be deleted.
Indexed Sequential Data Files
Used for very large sequential data files. Records are stored in order of their key field, but
also stored with an index, which allows a search to jump straight to the correct block of
records in the file. Think of it like a book with an index that specifies the page number for
each chapter, or a bookshelf where books are ordered A-Z by author, but there are also
markers placed on the shelf for the start of each letter of the alphabet.
Random Access data files
In a random access data file each record is identified with a record number in sequence and
each record takes up the same amount of memory.
The computer therefore quickly access to any record by simply calculating its position in the
data file based on the record number and then directly accessing that record.
However, random access files can be wasteful of disk space if the data stored in each field
varies in length because space is allocated for the longest possible field in every record (the
field storing the data item MOUSE would occupy the same number of bytes as one storing
the data item COMPUTER).
8
GCSE Computing A451
Unit 5.1 – The Database Concept
www.mrfraser.org
Each time a new record is created it is simply added to the end of the file and the record
number increased by one. However, deleting a record would upset the numbering system
so this cannot be done. Instead the record is kept but the contents deleted. Before long,
quite a number of records will be 'blank' and a growing proportion of the data file becomes
wasted space.
Indexed data files
In an indexed data file the records do not have a fixed length, they match the length of the
data in the same way as a serial data file and there is no wasted space. However, the start
position of each record is stored in an index which is part of the file. This allows the
computer to quickly access any record in the same way as with a random access data file.
If a record is deleted it is left in the data file but the index entry is deleted. If a record is
altered then the updated record is simply added to the end of the data file and the index
updated.
The data file will eventually contain a lot of wasted data that is not indexed because it had
been deleted or edited. However it is relatively easy for a computer to re-write an indexed
data file data file, deleting all the un-indexed data and re-indexing the rest.
SUMMARY:
•
•
•
Serial data files are slow to access to particular records within the file but they make
efficient use of storage space.
Random access data files allow fast access to particular records within the file but
can be inefficient in their use of storage space when records are added and deleted.
Indexed data files allow quick and easy access and make efficient use of space.
However, the data file does need to be periodically re-written and re-indexed to
maintain this efficiency.
Keywords
Conceptual view
External view
Flat-file database
Hierarchical database
Relational database
Physical view
SQL
Structured Query Language
How the data is organised in a database.
What the user sees of a database application.
A database of only one table.
A database organised on a tree structure with multiple
linked tables.
A database with multiple tables linked by common fields.
How the data is stored on the secondary storage.
A way to program queries to interrogate, maintain and set
up a database.
9