27
Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Embed Size (px)

Citation preview

Page 1: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Database Modeling

IT Key Ideas, Dynamic Database Systems, 2002

Chapter 8

Page 2: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Location Address Suburb Phone Date Starting TimeClareview School 13 Albert St Clareview 8295 5554 8/3/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 9/3/2002 7:00 PMWilliamstown Function Centre 10 Main Way Williamstown 8297 3153 13/3/2002 8:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 15/3/2002 5:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 16/3/2002 6:00 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 21/3/2002 1:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 23/3/2002 7:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 30/3/2002 7:30 PMClareview School 13 Albert St Clareview 8295 5554 5/4/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 6/4/2002 7:00 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 20/4/2002 1:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 20/4/2002 7:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 27/4/2002 7:00 PMClareview School 13 Albert St Clareview 8295 5554 3/5/2002 6:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 4/5/2002 7:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 11/5/2002 6:30 PMClareview School 13 Albert St Clareview 8295 5554 7/6/2002 5:00 PM

Disk Jockey Appointments

IT Key Ideas, Dynamic Database Systems, 2002

1. How is the data ordered?2. Is any of the data repeated?

page 86

Page 3: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Location Address Suburb Phone Date Starting TimeClareview School 13 Albert St Clareview 8295 5554 8/3/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 5/4/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 3/5/2002 6:00 PMClareview School 13 Albert St Clareview 8295 5554 7/6/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 9/3/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 23/3/2002 7:30 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 6/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 20/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 4/5/2002 7:30 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 21/3/2002 1:00 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 20/4/2002 1:00 PMWilliamstown Function Centre 10 Main Way Williamstown 8297 3153 13/3/2002 8:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 15/3/2002 5:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 16/3/2002 6:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 30/3/2002 7:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 27/4/2002 7:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 11/5/2002 6:30 PM

IT Key Ideas, Dynamic Database Systems, 2002

page 86

1. How is the data ordered?

2. Is any of the data repeated?

3. How might it be possible to save time and space?

Page 4: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

The second, third, fourth and fifth occurrences of the data shown is redundant.

IT Key Ideas, Dynamic Database Systems, 2002

Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367

page 87

Page 5: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Location Address Suburb Phone Date Starting TimeClareview School 13 Albert St Clareview 8295 5554 8/3/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 5/4/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 3/5/2002 6:00 PMClareview School 13 Albert St Clareview 8295 5554 7/6/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 9/3/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 23/3/2002 7:30 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 6/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 20/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 4/5/2002 7:30 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 21/3/2002 1:00 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 20/4/2002 1:00 PMWilliamstown Function Centre 10 Main Way Williamstown 8297 3153 13/3/2002 8:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 15/3/2002 5:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 16/3/2002 6:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 30/3/2002 7:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 27/4/2002 7:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 11/5/2002 6:30 PM

redundant data

IT Key Ideas, Dynamic Database Systems, 2002

Page 6: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Location Address Suburb Phone Date Starting TimeClareview School 13 Albert St Clareview 8295 5554 8/3/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 5/4/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 3/5/2002 6:00 PMClareview School 13 Albert St Clareview 8295 5554 7/6/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 9/3/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 23/3/2002 7:30 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 6/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 20/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 4/5/2002 7:30 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 21/3/2002 1:00 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 20/4/2002 1:00 PMWilliamstown Function Centre 10 Main Way Williamstown 8297 3153 13/3/2002 8:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 15/3/2002 5:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 16/3/2002 6:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 30/3/2002 7:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 27/4/2002 7:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 11/5/2002 6:30 PM

IT Key Ideas, Dynamic Database Systems, 2002

What does this data belong to or have in common?

it is all about? the Function Centres

The name is not necessarily straightforwardit might be called Locations or …

Page 7: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Location Address Suburb Phone Date Starting TimeClareview School 13 Albert St Clareview 8295 5554 8/3/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 5/4/2002 5:00 PMClareview School 13 Albert St Clareview 8295 5554 3/5/2002 6:00 PMClareview School 13 Albert St Clareview 8295 5554 7/6/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 9/3/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 23/3/2002 7:30 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 6/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 20/4/2002 7:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 4/5/2002 7:30 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 21/3/2002 1:00 PMSulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 20/4/2002 1:00 PMWilliamstown Function Centre 10 Main Way Williamstown 8297 3153 13/3/2002 8:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 15/3/2002 5:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 16/3/2002 6:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 30/3/2002 7:30 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 27/4/2002 7:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 11/5/2002 6:30 PM

IT Key Ideas, Dynamic Database Systems, 2002

What does this data belong to or have in common?

it is all about?

Appointments

Page 8: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

1.x

IT Key Ideas, Dynamic Database Systems, 2002

A relational database system avoids data redundancy by storing the data that belongs to different entities into separate tables.

systems with multiple tables page 87

Page 9: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

1.x

IT Key Ideas, Dynamic Database Systems, 2002

An entity according to the dictionary means “a thing” or “a being” or a “creature”.

The taxation office lists an individual, a partnership, an association, a corporation and a company as examples of entities.

Entities

IT Key Ideas, Dynamic Database Systems, 2002

page 87

Page 10: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

1.x

IT Key Ideas, Dynamic Database Systems, 2002

A key field is an element of data in a table that uniquely defines a record.

Key fields page 87

Page 11: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

which field?

Page 12: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

1.x

IT Key Ideas, Dynamic Database Systems, 2002

There will often be different fields that could be set as a key field. Such fields are called candidate keys, as they are just that, candidates for the key field.

Candidate keys page 87

Page 13: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

IT Key Ideas, Dynamic Database Systems, 2002

FunctionsLocation Address Suburb Phone

Clareview School 13 Albert St Clareview 8295 5554Clareview School 13 Albert St Clareview 8295 5554Clareview School 13 Albert St Clareview 8295 5554Clareview School 13 Albert St Clareview 8295 5554Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367Sulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819Sulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819Williamstown Function Centre 10 Main Way Williamstown 8297 3153Zervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696Zervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696Zervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696Zervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696Zervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696

There are several candidate keys for the entity about the functions.

Namely

• the Name of the location• the Address

• the Phone Number

Note:

• the Suburb is not

because two (or more) Function Centres could be in the one suburb

Page 14: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

or a new field may be created

eg.

• Location ID

• Location Code

• Function Centre ID

NB: this is the more likely approach at this level

Page 15: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Location Address Suburb Phone Date Starting TimeClareview School 13 Albert St Clareview 8295 5554 8/3/2002 5:00 PMMayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367 5/4/2002 5:00 PMWilliamstown Function Centre 10 Main Way Williamstown 8297 3153 3/5/2002 6:00 PMZervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696 7/6/2002 5:00 PM

9/3/2002 7:00 PM23/3/2002 7:30 PM6/4/2002 7:00 PM

20/4/2002 7:00 PM4/5/2002 7:30 PM

Sulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819 21/3/2002 1:00 PM20/4/2002 1:00 PM13/3/2002 8:00 PM16/3/2002 5:30 PM16/3/2002 6:00 PM30/3/2002 7:30 PM27/4/2002 7:00 PM11/5/2002 6:30 PM

the first four fields form one entity

this data is saved in one table

IT Key Ideas, Dynamic Database Systems, 2002

Page 16: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

namely

Function

Centre IDLocation Address Suburb Phone

CS Clareview School 13 Albert St Clareview 8295 5554MFCC Mayer Falls Civic Centre 5 Fifth Ave Mayer Falls 8349 3367WFC Williamstown Function Centre 10 Main Way Williamstown 8297 3153ZVCC Zervaas Valley Civic Centre 6 Regency Tce Zervaas Valley 8270 7696SCS Sulleyvale Combined School 4 Young Lane Sulleyvale 8296 0819

Note: The existence of the Function Centre ID field.

IT Key Ideas, Dynamic Database Systems, 2002

Page 17: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

the other fields form a second entity possibly called,

Function Centre

ID Date Starting Time

CS 8/3/2002 5:00 PMMFCC 9/3/2002 7:00 PMWFC 13/3/2002 8:00 PMZVCC 16/3/2002 5:30 PMZVCC 16/3/2002 6:00 PMSCS 21/3/2002 1:00 PMMFCC 23/3/2002 7:30 PMZVCC 30/3/2002 7:30 PMCS 5/4/2002 5:00 PMMFCC 6/4/2002 7:00 PMMFCC 20/4/2002 7:00 PMSCS 20/4/2002 1:00 PMZVCC 27/4/2002 7:00 PMCS 3/5/2002 6:00 PMMFCC 4/5/2002 7:30 PMZVCC 11/5/2002 6:30 PMCS 7/6/2002 5:00 PM

Note: the existence of the Function Centre ID, in order to be able to track where the appointments are.

IT Key Ideas, Dynamic Database Systems, 2002

Appointments

this data is saved in a second table

Page 18: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Relating the tables

page 90

Page 19: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

setting a primary key page 90

• select Design View for the Function Centres table

• select the Function Centre ID field

• click on the primary key button on the Toolbar

IT Key Ideas, Dynamic Database Systems, 2002

• save the table

Page 20: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

relating the tables page 91

• select the relationship button on the toolbar

IT Key Ideas, Dynamic Database Systems, 2002

• add both tables (use the Shift key) and close

• select the primary key field from the Function Centres table

• drag and drop this field to its matching field in the Appointments table(its foreign key)

Page 21: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Referential Integrity page 91

Data integrity involves ensuring the data is accurate, reliable, appropriate, correct.

IT Key Ideas, Dynamic Database Systems, 2002

Referential integrity involves ensuring that a record in the transaction table does not refer to a source entity that does not exist in the source table.

In this case, making sure that an Appointment is not entered for a non-existent Function Centre.

Page 22: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

IT Key Ideas, Dynamic Database Systems, 2002

page 97 Exercise 8.2

Data type, size, defaults, validation

Data Element Type SizeDefault value

(if appropriate)Validation Rule (if appropriate)

Date of Birth Date/Time

Date of Sale Date/Time

Time of Ride Date/Time

Gender Text

Test Percentage Number

Temperature Number

Returned Status Boolean

Booking Date Date/Time

Page 23: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

IT Key Ideas, Dynamic Database Systems, 2002

Data type, size, defaults, validation

Year Published Number

Studio Number

Test Status Boolean

Fun Run Time Date/Time

Year of Manufacture Number

Student Vote Number

Ensuite Boolean

Date of Birth Date/Time

Bank Withdrawal Number

Page 24: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

IT Key Ideas, Dynamic Database Systems, 2002

page 98 Practical 8.3 Cleaners

Page 25: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

IT Key Ideas, Dynamic Database Systems, 2002

Cleaners Data

Dictionaries

Companies Table

Name Type Size FormatCompany ID Text 6Company Text 30Address Text 25Suburb Text 25Phone Number Text 10 @@@@\ @@@@

Fax Number Text 10 @@@@\ @@@@

Contacts Table

Name Type Size FormatContact ID Text 12First Name Text 20Surname Text 25Position Text 30Department Text 30Phone Number Text 10 @@@@\ @@@@

Fax Number Text 10 @@@@\ @@@@

Company ID Text 6

Cleaning Occurrences Table

Name Type Size FormatContact ID Text 25Date Date/Time 8Start Time Date/Time 8Duration Single 4

Page 26: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

IT Key Ideas, Dynamic Database Systems, 2002

page 101 Exercise 8.4 Private Detectivepage 102 Exercise 8.5 City Tourspage 103 Exercise 8.6 Video Storepage 104 Exercise 8.7 Chauffeur Service

Page 27: Database Modeling IT Key Ideas, Dynamic Database Systems, 2002 Chapter 8

Chapter 8

********************************

IT Key Ideas, Dynamic Database Systems, 2002