copyright, harris corporation & ophir frieder, 19981 relational definitions

20
Copyright, Harris Corporation & Ophir Frieder, 1998 1 Relational Definitions

Upload: victoria-gray

Post on 18-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19981

Relational Definitions

Page 2: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19982

Objectives

• To define basic relation terms including entity, attribute, domain, relation, relational scheme, and functional dependency.

Page 3: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19983

Relational Terminology

• A domain is a set of scalar values, all of the same type.

Examples:

US city names - {San Diego, Miami, etc}

The names of US States - {Texas, New York, etc}

City populations - {1,2,3,...} (positive integers)

Page 4: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19984

Relational Terminology, Cont.

• A relation is a subset of the Cartesian product of one or more domains.

Example:

{(San Diego,California,2655463), (Miami,Florida,3514403), (Syracuse,New York,745691)}

Page 5: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19985

Relational Terminology, Cont.

• A tuple is one member of a relation.

Example:

(Miami,Florida,3514403)

Page 6: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19986

Relational Terminology, Cont.

• It is helpful to view a relation as a table, where each row is one tuple and each column is one attribute.

Note that the relation may not actually correspond to one table in the final design - for the purposes of performance it may be combined with other tables, or broken into multiple tables.

• A relational scheme is the set of attributes associated with a relation.

Page 7: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19987

Example - Relations

CITY STATE POPULATION

San Diego California 2655463

Miami Florida 3514403

Syracuse New York 745691

Page 8: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19988

Functional Dependencies

• Depending on the meaning of the attributes some subsets of the Cartesian product are not valid relations.

CITY STATE POPULATION

San Diego California 2655463

Pittsburgh Florida 3514403

Syracuse New York 745691

Page 9: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 19989

Functional Dependencies, Cont.

• Let R be a relational scheme with attributes A1, A2,..., An .

• Let X and Y be subsets of {A1, A2,..., An}.

• We say that Y is functionally dependent on X in R, denoted X=>Y, if it is not possible for two distinct tuples in R to have the same value for the attributes in X, and different values for the attributes in Y. Alternatively, we say X functionally determines Y.

• Informally, if you know the left-hand-side, then you know the right-hand-side.

Page 10: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199810

Functional Dependencies, Cont.

SS# => NAME

SS# => DATE-OF-BIRTH

SS# NAME DATE OF BIRTH

032446254 Mary Smith 11/4/68

045242453 Bob Jones 3/27/95

932415223 Sue Clark 8/3/76

Page 11: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199811

Functional Dependencies, Cont.

• Note that the two functional dependencies:

SS# => NAME

SS# => DATE-OF-BIRTH

• Could be represented by the single functional dependency:

SS# => NAME, DATE-OF-BIRTH

• Both representations have advantages, and will be used as appropriate.

Page 12: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199812

Functional Dependencies, Cont.

• What are all of the possible functional dependencies for the relational scheme R=(SS#,NAME,DATE-OF-BIRTH)?

• Which of these hold “in the real world?”

Page 13: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199813

Functional Dependencies, Cont.

• Functional dependencies are a result of what the attributes mean.

• A functional dependency is a statement about a relational scheme (i.e., all possible relations), and cannot be deduced from a particular relation.

• A functional dependency is said to be trivial if .

• Some functional dependencies can be enforced by a DataBase Management System (DBMS).

X Y X Y

Page 14: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199814

Candidate KeyAn Informal Definition

• Let R be a relational scheme. A candidate key for R is a subset of the set of attributes of R, say K, such that

– Uniqueness property:

No two distinct tuples of R have the same value for K.

– Irreducibility property:

No proper subset of K has the uniqueness property.

Page 15: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199815

Candidate Key, Cont.

• SS# is a candidate key for the following.

SS# => NAME

SS# => DATE-OF-BIRTH

SS# NAME DATE OF BIRTH

032446254 Mary Smith 11/4/68

045242453 Bob Jones 3/27/95

932415223 Sue Clark 8/3/76

Page 16: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199816

Candidate Key, Cont.

• Which of the following would be candidate keys?

SS#

NAME

DATE-OF-BIRTH

SS#, NAME

SS#, DATE-OF-BIRTH

NAME, DATE-OF-BIRTH

Page 17: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199817

Candidate KeyA More Formal Definition

• Let R be a relational scheme with attributes A1, A2,..., An and functional dependencies F. In addition, let X be a subset of A1, A2,..., An. Then X is a candidate key for R if

– X => A1, A2,..., An is in F+, and

– for no proper subset Y of X is it the case that Y => A1, A2,..., An is in F+.

Page 18: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199818

Closure Of A Set Of Dependencies

Question: What is F+?

Answer: F+ is the closure of F - the set of all dependencies derivable from F.

Equivalently, F+ is the set of all dependencies that follow from F by Armstrong’s

axioms.

Page 19: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199819

Armstrong’s Axioms

Tangent!

Let R be a relational scheme with attributes U and functional dependencies F.

•Reflexivity - If Y is a subset of X, then X=>Y.

•Augmentation - If X=>Y, and Z is a subset of U, then XZ=>YZ.

•Transitivity - If X=>Y and Y=>Z, then X=>Z.

Page 20: Copyright, Harris Corporation & Ophir Frieder, 19981 Relational Definitions

Copyright, Harris Corporation &

Ophir Frieder, 199820

Keys - Additional Terminology

• Often times a relation will have more than one candidate key. In such cases one is sometimes designated as the primary key.

• Any superset of a candidate key is often times referred to as a superkey.

• Some authors will refer to any candidate key as simply a key, while others will use this to refer to a primary key.

• Throughout this course, the term key will be used synonymously with the phrase candidate key.