DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

31
DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1

Transcript of DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

Page 1: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DATABASE LOGICAL

DESIGN -- II

Chandra S. Amaravadi

1

Page 2: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DESIGN CONCEPTS

NORMAL FORMSREPEATING GROUPS

PARTIAL DEPENDENCIESTRANSITIVE DEPENDENCIES

MULTI-VALUED DEPENDENCIES

2

Page 3: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

NORMALIZATION

unnormalizedunnormalized

1st NF1st NF

2nd NF2nd NF

3rd NF3rd NF

BCNFBCNF

4th NF4th NF

RemoveRemove

R.G.R.G.

RemoveRemove

P.D.P.D.

Remove Remove

T.D.T.D.

Remove other Remove other

anomaliesanomalies

RemoveRemove

M.V.DM.V.D

3

Normalization:The processof removingunwantedfunctionaldependencies.

Also:The processof designingwell-structuredtables.

Normal Forms:Normal formsare stages innormalization

Page 4: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

NORMAL FORMS

1st NF -- No repeating groups 2ndNF -- No partial dependencies (& no r.g.) 3rdNF -- No transitive dependencies (& no r.g., no p.d.) 4thNF -- No Multi-valued dependencies

(no r.g., no p.d., no t.d.)

BOYCE CODD NORMAL FORM (BCNF) --

Each and every determinant is a candidate key

4

Normal forms are stages in the normalization of a table

Consideronly firstthree duringdesign

Page 5: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DESIGN CONCEPT

Repeating group:A table with more than one set of values at row and column

intersection.

Repeating groups cause anomalies and must be removed

FLIGHTS

5

Flt# Origin Destination Fare

226 St. Louis Orlando $1250$850

328 Chicago Boston $1200$475

Page 6: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DOES THIS HAVE R.G.?

FLIGHTS

6

Flt# Origin Destination Fare

226 St. Louis Orlando $1250

226 St. Louis Orlando $850

328 Chicago Boston $1200

328 Chicago Boston $475

Page 7: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

NORMALIZED TABLES

FLIGHTS

FARES

Repeating groups are dealt withby removing the r.g. along withprimary key and putting it ina separate table.

7

Flt# Origin Destination

226 St. Louis Orlando

328 Chicago Boston

Flt# Fare

226 $1250

226 $850

328 $1200

328 $475

Page 8: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

Partial dependency :

An attribute (a non-key attribute) is dependent on part of the pkey.

DESIGN CONCEPTS..

Example: Suppose a & b form the primary key and c depends only on a

a, b cideal case

a, b cc depends only on a

8

Page 9: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

PARTIAL DEPENDENCY..

Example: Emp_id and course_title is the primary key, and salary and

Date course was taken are attributes,

Emp_id, Course_title Salary , date taken

Remove the p.d. and store it along with its determinant

9

Page 10: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

10

EID course title salary dt. taken

73890 SPSS 70,000 5/25/15

78931 DB2 75,000 5/25/15

78931 MYSQL 75,000 6/30/15

83722 DB2 60000 6/15/15

PARTIAL DEPENDENCY..

EMPLOYEES

Page 11: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

11

NORMALIZED TABLESEMPLOYEE

EMP COURSE

EID salary

73890 70,000

78931 75,000

83722 60,000

EID Course title Dt. taken

73890 SPSS 5/25/15

78931 DB2 5/25/15

78931 MYSQL 6/30/15

83722 DB2 6/15/15

Page 12: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

Transitive dependency :

An attribute is dependent on a non-key attribute

DESIGN CONCEPTS..

In A, a1 is pkey and a2 --> a3

a1 a2 in this casea3

a1 a2 a3 ideal case

Remove the t.d. and store it along with its determinant

12

Page 13: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

TRANSITIVE DEPENDENCY..

flt#, origin destination distance

Example: Flt# is the primary key, in a relation that consists of Flt#,

From, To, and Distance

13

flt# origin dest. dist.

223 Boston Seattle 1,800mi

224 Boston LA 2,100mi

234 Boston Seattle 1,800mi

FLIGHTS

Page 14: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

14

NORMALIZED TABLES..FLIGHTS

DISTANCE

flt# origin dest

223 Boston Seattle

224 Boston LA

234 Boston Seattle

origin destination distance

Boston Seattle

Boston LA

Page 15: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

15

TRANSITIVE DEPENDENCY..

isbn#, title pubcode pubname

Example: isbn# is the primary key, in a relation that consists of

title, pubcode and pubname.

isbn# title pub code pub name

890-0944423 MS Excel 1023 McGraw Hill

891-0928333 Intro. to Access 1023 McGraw Hill

892-0938282 Java programming 1038 Elsevier

BOOKS

Page 16: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

16

NORMALIZED TABLES..BOOKS

PUBLISHERS

isbn# title publisher

890-0944423 MS Excel 1023

891-0928333 Intro to Access 1023

892-0938282 Java Programming ??

pubcode pubname

Is this design correct?

Page 17: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

Multi-valued dependency:

If there are three or more attributes (‘a’, ‘b’, ‘c’) in a relation such

that for each “a” there are multiple values of “b” and for

each “a” there are multiple values of “c” and ‘b’ and ‘c’ are

independent then a MVD occurs

DESIGN CONCEPTS..

In A, a -->> b,

a -->> c

b & c are independent

a relation consists of three or more attributes (a, b, c..) b and c are multi-valued non-key attributes are independent of one another

17

Page 18: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

MULTI-VALUED DEPENDENCIES..

Flt#, Fare Meals

Example: Flt# is the primary key, in a relation that consists of Flt#,

Fare, Meals

SID#, SGPA C#

18

Fares (flt#, fare)Meals (flt#, meals)

Student (SID#, sgpa)Course (SID#, c#)

Is this Correct?

Page 19: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

FOR DISCUSSION

ord#: Unique identifier for order (an order can be for many parts)ord dt: date of orderp#: unique number for partsqty: # of a certain part that is ordered c# : container for finished parts (one container per part)#fin: # of finished partsdie#: Die used to manufacture parts (one die per part)shelf#: the shelf where the die is located

19

Identify problems (if any) with the following tables and their normal forms

Orders (ord#, p#, ord_dt, ord_amt)Order(ord#, ord dt., qty) Order(ord#, ord dt., p#) Parts(p#, #finished, c#, die#) Ord_for_parts (ord#, p#, descr, qty)Die(die#, shelf#, p#) Die(die#, shelf#)

Page 20: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

THE DESIGN PROCESS

20

Page 21: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

THE DESIGN PROCESS..

Start with the relation that has all the attributes Identify repeating groups Remove repeating groups along with their candidate key Identify partial dependencies Remove the dependency along with its candidate key Identify transitive dependencies Remove transitive dependency along with its candidate key

THE CONVENTIONAL APPROACH

You could alternatively use the FD approach to design

21

Page 22: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DESIGN EXAMPLES

Employee

Equipment

22

E ID Name Skills

1 John Programming,analysis

2 Jeff Programming,database

E# E_Descr P# P_Descr Qty

JD450 Bulldozer 100 chain 10

JD450 Bulldozer 200 crankshaft 40

JD550 Loader 200 crankshaft 40

Page 23: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

Instructor-Office

Course# Instructor Office

340 Banker St430

342 Banker St430

343 Banker St430

514 Koch St431

Assume each course has one instructor

23

DESIGN EXAMPLES..

Page 24: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

Employee

DESIGN EXAMPLES ..

24

EID NAME SKILLS HOBBIES

1. John Java skiing

DB2 jogging

2. Mary Geneva tennis

SQL server knitting

Page 25: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DESIGN EXAMPLES..

DRIVER NO.: DRIVER NAME:

CAR CLASS: DATE:

154 Unser

Sprint 11/09/XX

25

RACE # RACE DATE RACE RESULT CAR# OWNER

1 10/08 First 84 Gordon

2 10/08 Second 78 Sprint

3 10/08 First 84 Gordon

1 10/09 Last 54 Roy

-------- -------- -------- -------- --------

Page 26: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DESIGN EXAMPLE..

ASSUMPTIONS:

Each driver drives one car class.

There can be many races on a given date.

Each race is given a number valid for that date.

Each car has one owner.

A driver can drive for other owners in different races.

The database can be used to print similar reports on

other drivers.

26

Page 27: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

THIS SLIDE HAS BEEN

LEFT BLANK

27

Page 28: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

DISCUSSION QUESTIONS

Why is database design necessary? Can we carry out design without doing Normalization? What is a Functional Dependency? Can there be a functional

dependency between two records? What are anomalies? Are they desirable? Are anomalies removed after design? Are anomalies related to the degree of structure of a table? Can there be a partial dependency with a pkey that is simple? Can there be transitive dependency between the pkey and another

attr?

28

Page 29: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

29

REVIEW OF CONCEPTS

Basic Concepts Description

Normalization The process of removing unwanted functional dependencies. Also, the process of designing well-structured tables.

Normal forms Normal forms are stages in normalization

Repeating group A table with more than one set of values at row and column intersection.

Partial dependency An attribute (a non-key attribute) is dependent on part of the pkey.

Transitive dependency An attribute is dependent on a non-key attribute

Multi-valued dependency If there are three or more attributes (‘a’, ‘b’, ‘c’) in a relation such that for each “a” there are multiple values of “b” and for each “a” there are multiple values of “c” and ‘b’ and ‘c’ are independent then a MVD occurs

Page 30: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

30

Basic Concepts Description

1st NF No repeating groups

2nd NF No repeating groups, no partial dependencies

3rd NF No repeating groups, no partial dependencies, no transitive dependencies

if there are R.G., Unnormalized

If there are P.D. 1st NF

If there are T.D. 2nd NF

REVIEW OF CONCEPTS..

Page 31: DATABASE LOGICAL DESIGN -- II Chandra S. Amaravadi 1.

31