1 information systems: higher database systems. 2 adamsandrea d64 carluke...

29
1 Information Systems: Higher Database Systems

Upload: zoie-sliman

Post on 11-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

1

Information Systems: Higher

Database Systems

2

Adams Andrea D 64 Carluke Street,Jamestown Glasgow 0141 092 7721Baird Hamish J 7 Cedar Walk, Aberdeen 01224 928722Donald Lewis Y 8 Walker Road,Torry Aberdeen

01224 645182Hastings Paul I 12 Seaview Terrace, Aviemore 01479 971871Kind Shona E 159 Broomhill Court Aberdeen 01224 313148Lees Brian K RanchRock, Clearance Glasgow 0141 766 8621Robertson Roddy P 254 North Road, Culter Aberdeen 01224 651116St.John Ian W 18 Wilson Street,Muir Tain 01561 908727Holman Clare C 16a David Hall Elgin 01330 728716Williams Kirsten A 16 West Hillside Edinburgh 0131 972 4678

Table

Donald Lewis Y 8 Walker Road, Torry Aberdeen 01224 645182

A Simple Database

• A “flat-file” database contains only one table• Very simple structure to the data• Made up of records and fields

3

A Relational Database

• Data is stored in a set of tables• Tables are joined by relational links• This reduces duplication of data in

database• Also allows greater flexibility and

efficiency

4

Tables in a Relational Database

Borrower’s Library Number Borrower’s Name Borrower’s Address415109 Clark, K 92 Roast Drive, Westhlaw615181 Tove, J 17 Indian Road, Otley819187 Brannan, I 10 Hillview Crescent, Stonehaven

Book ISBN Book Title Author’s Name0-582-27544-X The Little Book of Tales Jones, Rachel1-625-91872-1 Close and Here Kinch, Justine7-910-14268-9 Cartoon Clips Quinn, Carol9-019-66278-1 Hackers Handbook Jackson, Iain

Loan Number Borrower’s Library Number Book ISBN Date Due Back22 415109 0-582-27544-X 23 February 200023 415109 1-625-91872-1 23 February 200024 819187 7-910-14268-9 26 February 200025 615181 9-019-66278-1 27 February 200026 415109 9-019-66278-1 3 March 200027 819187 1-625-91872-1 6 March 2000

5

Producing a Relational Database

• Analysis• identify and organise data• identify functions (I/P/O)

• Design• create database structures (including keys)• specify the characteristics of data and validity c

hecks.

• Implementation• implement structures and functions to create

database.• generate reports and evaluate system.

6

Data ModellingData modelling produces a plan for a database system that can be implemented using any relational database software.

1. Identify data in current system.2. Remove repeating groups by normalising the data.3. Determine relationships between data items and

create entity/relationship diagrams.4. Create a data dictionary to describe the data items

in the system.5. Identify the inputs, processes and outputs required

to make the system function.

7

Identify Primary Entities

• Primary entities are the groups of data items that make up the existing system.

• The key (or keys) that make each record in each entity unique are identified.

• The relationships between the entities are identified to allow normalisation later.

8

Normalisation

• Normalisation takes the data items (called attributes) of the existing entities and produces new entities that are easier to implement in a relational database.

• Generally, normalisation will produce a set of “real world” entities such as “Customers”, “Orders” etc.

9

First Normal Form• To place data into first normal form, we

remove any repeating groups within the primary entities.

• These repeating groups then become new entities, linked together by a one-to-many relationship.

• Relationships are created by including a primary key from one entity as a foreign key in another entity.

10

First Normal FormHere is un-normalised data from an existing system: -

Here is the same data in First Normal Form: -SalespersonsSalespersonNumber

SalespersonName

SalesArea

3462 Waters West3593 Dryne East

Customers and Sales-DetailsCustomerNumber

Customer Name WarehouseNumber

WarehouseLocation

Sales Amount SalespersonNumber

18765 Delta Systems 4 Fargo 13540 346218830 A. Levy and Son 3 Bismark 10600 346219242 Rainer and Co. 3 Bismark 9700 346218841 R. W. Flood Inc. 2 Superior 11560 359318899 Seward Systems 2 Superior 2590 359319565 Stodola’s Inc. 1 Plymouth 8800 359318765 Delta Systems 4 Fargo 8720 3593

11

RelationshipsRelationships can be one of three types:

One-to-One One-to-Many Many-to-Many

For example: one customer has one address one customer can place many orders. many salespersons can sell to many

customers.

12

Entity/Relationship Diagrams

• Entity - a collection of data (represented as a table in a database).

• Attribute - (a data item in an entity, a field in a database).

• Key Attribute - (an attribute that makes up the primary key or part of it).

• Relationship (a description of the relationship between two entities, normally from the one to the many side).

An Attribute An Entity A Key AttributeA

Relationship

13

Sample E/R Diagram

(Film NumberFilm Title

Film CertificateFilm Rental Cost)

(Video Tape Number*Film Number

Video Tape in Stock)

(Transaction Number*Customer Number

*Video Tape NumberDate Booked Out

Date Returned)

(Customer NumberCustomer Title

Customer FirstnameCustomer Initials

Customer SurnameCustomer Address

Customer Post CodeCustomer Tel. No.)

M

1

1 M

1 MCustomers

Films Video Tapes

are rented

on

make

Transactions

14

Data Dictionary

A dictionary is a collection of data about data (meta data).

It describes all the attributes and their properties: type required (or not) range format

15

Sample Data DictionaryEntity Attribute DescriptionCustomers Customer Number Unique customer identifier; Numbers in the range 1-

99999; required. Text only.Customer Title Customer title such as Mr, Mrs etc.; required. Text

only.Customer Firstname Firstname of customer; required; Text only.Customer Initial Initials of customer; May be omitted; Text only.Customer Surname Surname of customer; required; Text only.Customer Address All address details for customer excluding Post Code;

required. Text and NumbersCustomer Post Code Post code of customer; required. 8 characters matching

standard post code format.Transactions Transaction Number Unique transaction identifier; Numbers in the range 1-

9999999; required.Customer Number Identifier for an existing customer; required; see

Customers entity.Date Booked Out Required. Date only.Date Returned Is omitted until video tape is returned; Date only.Video Tape Number Identifier for an existing video tape; required; see Video

Tapes entity.

16

Functions (I/P/O)Functions that act on the database are

either input, processing or output operations e.g. Editing data is an input operation Carrying out a calculation is a process Producing a report based on the data is an

output.

All the functions that act on one, some or all of the entities are identified.

17

What can functions do?

Functions can be used to extend the capabilities of the database system beyond what the manual system currently does e.g. statistical reports can be produced data in entities can be cross-reference to

ensure integrity operations can be automated (such as

looking up over due books in a library system).

18

Example Functions

19

Database Design

The finished design will include.• data item names• database structure• data item characteristic• validity checks

This outcome is concerned with designing database structures for implementation.

Ensure that the design closely matches the data model produced during the analysis.

20

Choosing field and table names

Most relational database management systems have rules that govern how fields and tables are named.

An RDBMS may only allow field and table names of a particular length and may prohibit certain characters from being included in data item names.

For example, in Microsoft Access field and table names: Can be up to 64 characters long. Can include any combination of letters, numbers, spaces, and

special characters except a period (.), an exclamation point (!), an accent grave (`), and brackets ([ ]).

Can't begin with leading spaces. Can't include control characters (ASCII values 0 through 31).

21

Database Structure

• The structures designed for implementation in the RDBMS should match those in the analysis e.g.

Tables will be implemented from entities Fields will represent attributes Relationships between tables should be

established (one-to-many etc.) Functions should be created for the inputs,

processes and outputs identified.

22

Keys and Indexes• A primary key uniquely identifies each

record in a table.• A foreign key is a primary key from a table

included in another table to form a relationship.

• An index is a quick reference created by a RDBMS to speed up the use of the database.

• If the RDBMS has the facility to index fields then all foreign and primary keys should be indexed.

23

Data Item Characteristics

• Appropriate field types should be selected to meet the requirements of the data dictionary produced from the analysis.

• The field types must be selected from those available in the RDBMS e.g.

Dates should be represented using the Date type not Numbers.

Money should be represented using the currency data types.

24

Data types available in Microsoft Access

Data Type Description Size restrictionsText Text or combinations of text and numbers, as well as

numbers that don't require calculations, such as phonenumbers.

Up to 255 characters.

Memo Lengthy text or combinations of text and numbers. Up to 65,535 characters.Number Numeric data used in mathematical calculations. Can be

a real number of an integer.1, 2, 4, or 8 bytes.

Date/Time Date and time values for the years 100 through 9999. 8 BytesCurrency Currency values and numeric data used in mathematical

calculations involving data with one to four decimalplaces. Accurate to 15 digits on the left side of thedecimal separator and to 4 digits on the right side.

8 Bytes

AutoNumber A unique sequential (incremented by 1) number orrandom number assigned by Microsoft Access whenevera new record is added to a table. AutoNumber fields can'tbe updated.

4 bytes

Yes/No Yes and No values and fields that contain only one oftwo values (Yes/No, True/False, or On/Off).

1 bit.

OLE Object An object such as a document, audio, video or any otherobject linked to or embedded in a Microsoft Accesstable.

Up to 1 gigabyte (limitedby available disk space)

Hyperlink Text or combinations of text and numbers stored as textand used as a hyperlink address.

Each part of a Hyperlinkdata type can contain upto 2048 characters.

Lookup Value Creates a field that allows you to choose a value fromanother table or from a list of that you enter.

The same as the valueused in the lookup.

25

Validity Checks• Data entered into the database should be

valid and correct.

• Validity checks ensure that the data entered meets certain rules such as: Presence (if the data must be in the field or

not). Range (if the value entered is within a

particular range). Restricted choice (a value entered must be

from a specified list of possible values).

26

Detailed Data Dictionary

• The detailed data dictionary specifies how the data model will be implemented. It contains the following details about each field

• Name• Type• Size• Validation Check

• Format• Required (or not)• Indexed (or not)

27

Example Detailed Data Dictionary

Database: Charlie’s Video Club Table: Video TapesFieldname Type Size Validation Format Req’d IndexVideo Tape Number Autonumber Auto Yes Yes (unique)

Primary keyFilm Number Number Auto Lookup (from

Films Table)Yes Yes (foreign

key)Booked Out Yes/No Auto =Yes OR =

NoYes No

Database: Charlie’s Video Club Table: FilmsFieldname Type Size Validation Format Req’d IndexFilm Number Autonumber Auto Yes Yes (unique)

Primary keyFilm Title Text 75 Yes NoFilm Certificate Text 2 Lookup

(from E,U, PG, 12,15, 18)

Yes No

Film Rental Cost Currency Auto >=£1.00AND<=£99.99

£99.99 Yes No

28

Relationships between fields• Relationships between fields can be shown in the

following format.

[table.fieldname] 1:M [table.fieldname]• Relationships are shown as follows:

1:M (one-to-many)

M:M (many-to-many)

1:1 (one-to-one)• For example:[Customers.Customer Number] 1:M [Transactions.Customer Number][Video Tapes.Video Tape Number] 1:M [Transactions.Video Tape Number][Films.Film Number] 1:M [Video Tapes.Film Number]

29

Appropriate Design

• If you have completed the detailed data dictionary and specified the relationships between the fields in the tables whilst considering the restrictions placed on you by the RDBMS that you have successfully met this performance criterion.

• When you are designing the database structures for your implementation you must always consider what your RDBMS is capable of doing. There is no point in designing a system that cannot be implemented with the software that you have available.