database fundamentals lecture 5. the design process continued

11
Session 9: Approaches to Indigenous Health – a debate

Post on 21-Dec-2015

224 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Database Fundamentals Lecture 5. The Design Process continued

Database Fundamentals

Lecture 5

Page 2: Database Fundamentals Lecture 5. The Design Process continued

The Design Processcontinued

Page 3: Database Fundamentals Lecture 5. The Design Process continued

car driver

car driver

car driver

car driver

1:1 A car can only have one driver; a driver can have only one car.

1:M A car can have more than one driver; a driver can only have one car.

1:M A car can have only one driver; a driver can have more than one car.

M:N A car can have more than one driver; a driver can have more than one car.

Page 4: Database Fundamentals Lecture 5. The Design Process continued

many-to-many relationship

A many-to-many relationship cannot berepresented in a relational database.

Take the example from last week:

Page 5: Database Fundamentals Lecture 5. The Design Process continued

Sales Staff Customertake

orders

Sales Staff Customer

Order

accepts places

This many-to-many relationship does not enable mapping between a particular order and a particular member of the sales staff

The entity Order uniquely defines an instance involving both Sales Staff and Customer. From a single many-to-many relationship two one-to-many relationships have been created.

Page 6: Database Fundamentals Lecture 5. The Design Process continued

Sales Staff

Staffid

Name

DOB

Employ start date

Order

Orderid

Staffid*

Customerid*

Order details

Customer

Customerid

Name

Address

Contact name

Telephone

Foreign keys

Page 7: Database Fundamentals Lecture 5. The Design Process continued

Take another example:

takesstude

ntmodule

Each student has enrolled for one or more modulesANDEach module has enrolled on it zero or more students

This creates the following problem:

Page 8: Database Fundamentals Lecture 5. The Design Process continued

STUDENT(studentid,student name,pathway,module1,

module2, module3,module4……..)

MODULE(moduleid,moduleName, student1,student2,student3,student4………..)

Page 9: Database Fundamentals Lecture 5. The Design Process continued

The solution to this problem is to create a third relation that represents the relationship itself.

Such relations are called intersection relations because each row documents the intersection of a particular student with a particular module.

Page 10: Database Fundamentals Lecture 5. The Design Process continued

Student Module

Enrolment

is involved is for

Each student is involved in one or more enrolmentsand

Each enrolment involves one studentand

and Each enrolment is for one moduleand

Each module is involved in zero or more enrolments

Enrolment is an intersection table.

Page 11: Database Fundamentals Lecture 5. The Design Process continued

The entity and attributes are represented below:

STUDENT(studentid,studentName,pathway)MODULE(moduleid,moduleName)ENROLMENT(moduleid,studentid)

PRIMARY KEY - is an attribute or group of attributes that uniquely identifies each entity type, and each record in the corresponding database table.

COMPOSITE KEY – is when two fields together form the unique identifier.

Page 12: Database Fundamentals Lecture 5. The Design Process continued

•Entity-Relationship modelling is a top down approach to database development.

•It begins with study of the strategic goals of the organisation.

•From such a study, an abstract model is constructed.

•The higher level model is transformed into lower-level models.

•From these the application is developed.

Top-Down Development

Page 13: Database Fundamentals Lecture 5. The Design Process continued

Bottom-up Development

•Reverse of top-down development.

•Begins with the need to develop a specific system.

•Requirements specification established from which a data model is built.

•The database is then designed and implemented.

Page 14: Database Fundamentals Lecture 5. The Design Process continued

•Putting all data into one file or table led to logic problems when trying to manipulate the contained data.

•Normalisation is a technique for analysingrelations based on:

Primary keysFunctional dependencies

•Series of rules

Normalisation(Bottom-up development)

Page 15: Database Fundamentals Lecture 5. The Design Process continued

For example: Orders database

OrderDate OrderNumberOrderQuantity1Productid1ProductDetail1ProductName1ProductPrice1OrderQuantity2Productid2ProductDetail2ProductName2ProductPrice2 CustomeridCustomerName

First Normal Form (1NF)Rule:

All repeating groups should be eliminated and put into separate tables

Order

Page 16: Database Fundamentals Lecture 5. The Design Process continued

OrderDate OrderNoOrderQuantity1Productid1ProductDetail1ProductName1ProductPrice1OrderQuantity2Productid2ProductDetail2ProductName2ProductPrice2 CustomeridCustomerName

Order

FROM THIS TO THIS

Order

OrderNoOrderDateCustomeridCustomerName

OrderDetail

ProductidProductDetailProductPriceOrderQuantity

Page 17: Database Fundamentals Lecture 5. The Design Process continued

Eliminating Data Repetition in a Database

Order

OrderNoOrderDateCustomeridCustomerName

To enable these tables to relate to one another it is necessary thatboth contain a common field.

OrderDetail

ItemNoProductidProductDetailProductPriceOrderQuantity

Page 18: Database Fundamentals Lecture 5. The Design Process continued

First Normal Form (1NF) -continued

Order

Now a one-to-many relationship has been established. You are no longer obliged to add a new order every time you add a new order item. One row in the OrderDetail table needs both ProductName & OrderNumber to identify it. Both fields are the primary key i.e.composite key

OrderNoOrderDateCustomeridCustomerName

OrderDetail

ProductidOrderNoProductDetailProductPriceOrderQuantity

Page 19: Database Fundamentals Lecture 5. The Design Process continued

Order

OrderDetail

OrderNoOrderDateCustomeridCustomerName

ProductidOrderNoProductDetailProductPriceOrderQuantity

Second Normal Form(2NF)

Rule: All partial dependenciesmust be eliminated and separated into their own tables.

Page 20: Database Fundamentals Lecture 5. The Design Process continued

Eliminating Partial Dependencies - Second Normal Form 2NF

OrderOrderNoOrderDateCustomeridCustomerName

OrderDetail

OrderNoProductidOrderQuantity

The OrderDetail table now contains a composite key (two fields become the primary key –

OrderNo and Productid. OrderQuantity isdependent on both the fields of the composite key

Product

ProductidProductDetailProductPrice

Page 21: Database Fundamentals Lecture 5. The Design Process continued

Third Normal Form (3NF)Rule: to eliminate and separate anydata that is not key. All values must be uniquely identified by the key. In this example the Order table contains the Customeridand CustomerName. This data could be separated from the current table and put in to its own table.

OrderOrderNoOrderDateCustomeridCustomerName

OrderNoProductidOrderQuantity

OrderDetail

ProductProductid

ProductDetailProductPrice

Page 22: Database Fundamentals Lecture 5. The Design Process continued

Uniquely Identifying all values -Third Normal Form (3NF)

CustomeridCustomerName

Customer

Order

OrderNoOrderDateCustomerid*

OrderNoProductidOrderQuantity

OrderDetail Product

Productid ProductDetail ProductPrice

Customerid links the Order table with The Customer table. Customerid is the primary key in the Customer table and Foreign key in theOrder table

Page 23: Database Fundamentals Lecture 5. The Design Process continued

Places Item on

Contains

Entity Relationship Model (E-RM)

Customer

OrderDetail

Order

Product

Page 24: Database Fundamentals Lecture 5. The Design Process continued

Take the Unnormalised student table below to 3NF.StudentidStudentNamePathwayPathwayTutoridPathwayTutorNamePathwayTutorOfficeModuleCode1ModuleName1FinalGrade1ModuleCode2ModuleName2FinalGrade2

Page 25: Database Fundamentals Lecture 5. The Design Process continued

Possible answer

StudentidStudentNamePathwayPathwayTutoridPathwayTutorNamePathwayTutorOffice ModuleCodeModuleNameFinalGrade

Page 26: Database Fundamentals Lecture 5. The Design Process continued

1NF - Eliminating Repeating groups

StudentidStudentNamePathwayPathwayTutoridPathwayTutorNamePathwayTutorOffice

StudentidModuleCodeModuleNameFinalGrade

Student Grade

Page 27: Database Fundamentals Lecture 5. The Design Process continued

2NF- Eliminating partial dependencies.

StudentidStudentNamePathwayPathwayTutoridPathwayTutorNamePathwayTutorOffice

ModuleCodeStudentidFinalGrade

Student Grade Module

ModuleCodeModuleName

Page 28: Database Fundamentals Lecture 5. The Design Process continued

3NF - Uniquely Identifying all values

StudentidStudentNamePathwayPathwayTutorid*

ModuleCodeStudentidFinalGrade

Student Grade

PathwayTutoridPathwayTutorNamePathwayTutorOffice

Tutor

Module

ModuleCodeModuleName

Page 29: Database Fundamentals Lecture 5. The Design Process continued

Takes

PathwayTutors Results inObtains

Student Module

GradeTutor

E-RM

Page 30: Database Fundamentals Lecture 5. The Design Process continued

Practical 5

Artworks Database

(Written senario included with Practical 5 details)

Page 31: Database Fundamentals Lecture 5. The Design Process continued

Artworks Database

CUSTOMER (customerid, lastname, firstname, address1, address2, address3, postcode, telephone)

WORK (workid, artistid, copy, description, boughtDate, boughtPrice)

TRANSACTION (transactionid, workid, customerid, saleDate, salePrice)

ARTIST (artistid, lastname, firstname, nationality, dob, dod)CUSTOMER-ARTIST-INT (customerid, artistid)

Page 32: Database Fundamentals Lecture 5. The Design Process continued

makes

1N

creates

produces

interests

interested in

Artworks Gallery E-R Model

Transaction

Customer

Customer-Artist-Int

Artist

Work