Top Banner
1 Database Management Systems Session 5
26

1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

Dec 31, 2015

Download

Documents

Caroline Waters
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

1

Database Management Systems

Session 5

Page 2: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

2

Objectives

1. Understand the structure of a data table2. Understand data normalisation3. Understand and use the terms:

- entity- attribute- field- record- primary key

4. Understand the principle of linking tables in a relational database

Page 3: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

3

Topics

1. Database Tables

2. Normalisation

3. Linking Tables

4. Database Schema

Page 4: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

4

Address Book

Name

Address

Tel FAX

Mobile

Email

Gertrude Jones

34 Great West RoadLondonW23 8RT

020 8564 1234

07814 100200

[email protected]

020 8564 1235

Record

Field

Data

Page 5: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

5

Contacts TableName Address Phone FAX Mobile Email

DarrenAdamson

6 Spring Gardens 020 7885 1236

 08562 100099 dadam@ahomesp.

co.uk

Gertie Jones

34 Great West Road, London W23 8RT

020 8354 1234

 07954 100200 gertie@somecomp

any.co.uk

Cedric Jones

34 Great West Road, London W23 8RT

020 8354 1234

 07951 111233 [email protected]

g

Jessie Wallace

18 Loch Arber Crescent, Edinburgh EH8 9OP

0123 266 5889

0123 889 7756

08962 333568 wallacej@servicepr

ov.net

Record

Field

Page 6: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

6

Entities and Attributes

• “I want to record the names and addresses of my contacts along with their phone numbers, FAX numbers, mobile numbers and their email addresses”

• Entity: Contact• Attributes of Contact:

- Name- Address- Phone- FAX- Mobile- Email

Page 7: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

7

Ordered Collection of Data

• Characteristics:- each Record is unique- repetition of data is avoided

• Database Tables follow certain rules called:- First Normal Form- Second Normal Form- Third Normal Form

Page 8: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

8

Primary Key

• A Field (or fields) which has a unique value for each record

• Eg. - National Insurance number- Car registration number- Passport number

Page 9: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

9

First Normal Form

• Data is atomic, self-contained and independent– No field in a table contains any repeating

groups– No record in a table contains repeating

groups

Page 10: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

10

Second Normal Form

• All the non-key columns must be dependent on the entire primary key

Page 11: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

11

Third Normal Form

• All the non-key columns of the table must be only dependent on the primary key and not on each other

Page 12: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

12

Identifying Entities and Relationships

• Read the scenario and pick out the nouns

• Pick out which nouns are giving information about another noun eg Name is telling you additional information about Contact

• In this case Contact is the Entity and Name is an Attribute of that Entity

Page 13: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

13

Exercise: Entities and Attributes

• Pick out the database entities and suggest useful attributes:

• A library has about 300 borrowers who complete a registration form when they join. There are about 25,000 books available for loan. A loan is for 2 weeks and may be renewed over the phone. Overdue books are charged at 10p per day. If a book is out on loan, another borrower may request it.

Page 14: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

14

Text Data

• For example the Name field

• The size of the field is determined by the maximum number of characters you want to store

• The size of the field is the same for each record so empty spaces waste storage space

Page 15: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

15

Number Data

• For Example in the Salary field

• The size of the field is determined by the maximum precision of the numbers you want to store– Integer– Long Integer– Single– Double

Page 16: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

16

Date Data

• Stored on the computer as a number

• Different Formats eg:Short date – 01/02/06

Page 17: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

17

Logical Data

• Otherwise known as ‘Yes/No’

• Takes up minimal storage space

Page 18: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

18

Sorting on Text Data

• Yellow• 22• 3• Apple• A plum

• 22• 3• A plum• Apple• Yellow

Sort Ascending

Page 19: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

19

Points to Consider

• What type of data is a telephone number?

• How can you name files on a Windows system with digits so that they sort correctly?

Page 20: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

20

Linking on the Primary Key

Customer

Customer IDName

AddressPhone

Credit Limit

Purchase

Purchase IDCustomer ID

DateItem

Amount

PK PK

Page 21: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

21

Linked Fields

Customers

Customer ID Name

1 Felipe Martins

2 Tom Smith

3 Kimberley Brown

4 Steve Hammer

5 Alfred Futterkist

Purchases

Purchase ID

Customer ID Item

1789 3 Fig Rolls

1790 2 Arabiata Sauce

1791 3 Black Olives

1792 3Porcini

Mushrooms

1793 5 Smoked Salmon

1794 4 Cod Roe

1795 1 Cured Ham

1796 3 Sugar Snap Peas

1797 1 Ginger Beer

1798 5 Ground Cumin

One to Many Relationship

Linked Fields

Page 22: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

22

Most Common Types of Relationship

CustomerEmployeePurchase

Staff

Contractor

One to ManyWhere one record in one tablelinks with many in the other table

One to OneWhere one record in one tablelinks with one in the other table

Page 23: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

23

Many to Many Relationship

Borrower Book

Many to Many LinkA borrower can borrow many books and a book may be borrowed by many borrowers – over a period of time

Page 24: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

24

Resolving Many to Many Relationships

Many to Many Links are impossible to programme into a database system.

This type of relationship may be resolved into 2 many to one relationships.

Borrower Loan Book

Page 25: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

25

Scenario

• Draw an E-R diagram:• Northwind is a wholesaler of delicatessen

products. Customers are all over the world and each member of the sales team may deal with any customer. Products is kept in a central warehouse and items are ordered from Suppliers when numbers reach the re-order level. An Order may consist of several different products and may be delivered by any one of three Shippers.

Page 26: 1 Database Management Systems Session 5. 2 Objectives 1.Understand the structure of a data table 2.Understand data normalisation 3.Understand and use.

26

Entity-Relationship Diagram