Download presentation

Presentation is loading. Please wait.

Published byJadon Wilding Modified over 3 years ago

2
Main concepts of relational model

3
The relational model was proposed in 1970 by Edgar Codd The relational model assumes that data is stored in two-dimensional tables called relations As an example, information about company cars (vehicle identification number, number plate, mark and year) can be stored in the following relation: VINNUMBER_PLATEMARKYEAR GTRE545WRTH256452EPA60PLFord Fusion I2003 THER186ACVG636853EL432PLOpel Corsa II2005 WDH144TETU063632EZG42PLCitroen C3 III2011

4
Definition (Relation schema): Let R be a finite set of elements A 1,A 2,...,A n called attributes. Each A i (i=1..n) is assigned to the set of values D(A i ) called the domain of A i. The set R is called a relation schema. Example 1 (Relation schema): STUDENT:={INDEX_NO, FIRST_NAME, LAST_NAME, YEAR, FACULTY} D(INDEX_NO):= {927502, 138571, 714072, 841053, 595723, 965024}, D(FIRST_NAME):= {David, Agnes, Andrew, Charles, Eva, Clara}, D(LAST_NAME):= {Holl, Lewis, Harris, Klark, Barker, Morgan}, D(YEAR):= {1, 2, 3}, D(FACULTY):= {Mathematics, Computer Science, Management, Law, Economics, Physics, Chemistry, Biology}.

5
Definition (Tuple): Consider the relation schema R:={A 1,A 2,...,A n } and the set D(R) := D(A 1 ) ∪ D(A 2 ) ∪… ∪ D(A n ). Let f: R D(R) be a function such that f(A i ) D(A i ) for each i=1..n. The function f is called a tuple. Tuples defined on R will be denoted by r, r 1, r 2, s, t,.... Table representation of tuples Let r be a tuple defined on R={A 1,A 2,...,A n }. r is a function so it can be expressed as r = {(A 1,r(A 1 )), (A 2,r(A 2 )),...,(A n,r(A n ))} where r(A i ) D(A i ), i=1,...,n. This notation implies the following table representation of r: A1A1 A2A2... AnAn r(A 1 )r(A 2 )... r(A n )

6
Definition (Relation): Let T(R) denotes the set of all tuples defined on the set R. A finite subset of the set T(R) is a called a relation with the schema R. This subset is also called an instance of the schema R. Relations with the schema R (instances of R) will be denoted by I, J, K,.... Table representation of relations Let I be a relation with the schema R={A 1,A 2,...,A n }. According to the definition I:={r 1, r 2,...,r m }, where r i : R D(R), r i (A j ) D(A j ), i=1,...,m, j=1,...,n. Since each r i function has the same set of arguments, therefore relation I can be described by the following table: A1A1 A2A2... AnAn r 1 (A 1 )r 1 (A 2 )... r 1 (A n ) r 2 (A 1 )r 2 (A 2 )... r 2 (A n )... r m (A 1 )r m (A 2 )... r m (A n )

7
Example 1 (Relation) I(STUDENT):={ {138571, Eva, Klark, 2, Law}, {927502, David, Holl, 1, Biology}, {714072, Andrew, Lewis, 3, Computer Science}, {965024, Charles, Barker, 1, Mathematics} } is a relation with the STUDENT schema (I(STUDENT) is an instance of the STUDENT schema).

8
INDEX_NOFIRST_NAMELAST_NAMEYEARFACULTY 138571EvaKlark 2 Law 927502DavidHoll 1 Biology 714072AndrewLewis 3 Computer Science 965024CharlesBarker 1 Mathematics

9
Example 1 (cont. Relation) I(STUDENT):={ {138571, Eva, Klark, 2, Law}, {927502, David, Holl, 1, Biology}, {714072, Andrew, Lewis, 3, Computer Science}, {965024, Charles, Barker, 1, Mathematics} } is a relation with the STUDENT schema (I(STUDENT) is an instance of the STUDENT schema).

10
In the relational model the best known formal query languages are relational algebra and relational calculus. The relational algebra is based on a set of operators (e.g. selection, projection, join, union, intersect, etc.) which are applied to relation instances. Queries in relational algebra are expressed in the procedural manner: each query specifies a sequence of operations needed to compute the desired answer. The relational calculus provides a declarative manner of formulating queries. It assumes that a query specifies only the desired answer without describing a precise sequence of required operations.

11
The relation algebra specifies standard set operations (union, intersect, difference, cross product) which are applied to relations. Let R={A 1,A 2,...,A n } be a relation schema and let T(R) denotes the set of all tuples defined on R. Then the union, intersection, and the difference of relations I(R) and J(R) are defined as follows. Definition. I(R) J(R) := {r T(R); r I(R) r J(R)} (union) I(R) J(R) := {r T(R); r I(R r J(R)} (intersection) I(R)\J(R) := {r T(R); r I(R r J(R)} (difference)

12
Example 2 Consider the following instances I and J of PHONE:={PHONE_ID, NUMBER, MODEL} : R = {A 1,A 2,,A 3 } (R = PHONE, A 1 = PHONE_ID A 2 = NUMBER, A 3 = MODEL) D(A 1 )=D(PHONE_ID)={6,3,9,11}, D(A 2 )=D(NUMBER)={426235020, 491503592, 525246252, 426548716}, D(A 3 )=D(MODEL)={Siemens Gigaset W341, Sony Xperia WE, Nokia Lumia 329, Panasonic E425}, r 1 := {(A 1,r(A 1 )), (A 2,r(A 2 )),(A 3,r(A 3 ))}, r 1 := {(PHONE_ID,6), (NUMBER, 426235020),(MODEL, Siemens Gigaset W341)}, r 2 := {(A 1,r(A 1 )), (A 2,r(A 2 )),(A 3,r(A 3 ))}, r 2 := {(PHONE_ID,3), (NUMBER, 491503592),(MODEL, Sony Xperia WE)}, r 3 := {(A 1,r(A 1 )), (A 2,r(A 2 )),(A 3,r(A 3 ))}, r 3 := {(PHONE_ID,9), (NUMBER, 525246252),(MODEL, Nokia Lumia 329)}, r 4 := {(A 1,r(A 1 )), (A 2,r(A 2 )),(A 3,r(A 3 ))}, r 4 := {(PHONE_ID,11), (NUMBER, 426548716),(MODEL, Panasonic E425)}, I:={r 1,r 2,r 3 }, I(PHONE)={6, 426235020, Siemens Gigaset W341}, {3, 491503592, Sony Xperia WE}, {9, 525246252, Nokia Lumia 329}, {11, 426548716, Panasonic E425 }

13
I(PHONE) J(PHONE) I(PHONE) J(PHONE) I(R) J(R) := {rT(R); rI(R) rJ(R)} PHONE_IDNUMBERMODEL 6426235020Siemens Gigaset W341 3491503592Sony Xperia WE 9525246252Nokia Lumia 329 11426548716Panasonic E425 PHONE_IDNUMBERMODEL 1506923054Nokia Lumia 6556 3491503592Sony Xperia WE 4543012943Samsung Galaxy A45 PHONE_IDNUMBERMODEL 1506923054Nokia Lumia 6556 3491503592Sony Xperia WE 4543012943Samsung Galaxy A45 6426235020Siemens Gigaset W341 9525246252Nokia Lumia 329 11426548716Panasonic E425

14
I(PHONE) J(PHONE) I(PHONE) J(PHONE) I(R) J(R) := {r T(R); r I(R r J(R)} PHONE_IDNUMBERMODEL 6426235020Siemens Gigaset W341 3491503592Sony Xperia WE 9525246252Nokia Lumia 329 11426548716Panasonic E425 PHONE_IDNUMBERMODEL 1506923054Nokia Lumia 6556 3491503592Sony Xperia WE 4543012943Samsung Galaxy A45 PHONE_IDNUMBERMODEL 3491503592Sony Xperia WE

15
I(PHONE) J(PHONE) I(PHONE) \ J(PHONE) I(R)\J(R) := {r T(R); r I(R r J(R)} PHONE_IDNUMBERMODEL 6426235020Siemens Gigaset W341 3491503592Sony Xperia WE 9525246252Nokia Lumia 329 11426548716Panasonic E425 PHONE_IDNUMBERMODEL 1506923054Nokia Lumia 6556 3491503592Sony Xperia WE 4543012943Samsung Galaxy A45 PHONE_IDNUMBERMODEL 6426235020Siemens Gigaset W341 9525246252Nokia Lumia 329 11426548716Panasonic E425

16
The projection operator chooses a set of specified attributes from a given relation. Let R={A 1,A 2,...,A n } be relation schema and let P {A 1,A 2,...,A n }. Definition 2.4 (Tuple restriction) : A tuple s T(P) is called a restriction of r T(R) to P if and only if s(A i )=r(A i ) for each A i P. The tuple restriction is denoted by r[P].

17
Example 1 (cont. Tuple restriction) Let STUDENT:={INDEX_NO, FIRST_NAME, LAST_NAME, YEAR, FACULTY} be relation schema and let P {INDEX_NO, LAST_NAME, FACULTY}. Next let r = {138571, Eva, Klark, 2, Law} be a given tuple, then r[P] = {138571, Klark, Law} INDEX_NOFIRST_NAMELAST_NAMEYEARFACULTY 138571EvaKlark 2 Law INDEX_NOLAST_NAMEFACULTY 138571KlarkLaw

18
Definition (Projection) Given a relation I(R) and the set P R, the set P (I(R)) := {r T(P); (s I(R)) (r = s[P])} is called the projection of I(R) on P. Example 1 (cont. Projection) Let STUDENT:={INDEX_NO, FIRST_NAME, LAST_NAME, YEAR, FACULTY} be relation schema and let I(STUDENT):={ {138571, Eva, Klark, 2, Law}, {927502, David, Holl, 1, Biology}, {714072, Andrew, Lewis, 3, Computer Science}, {965024, Charles, Barker, 1, Mathematics} } be a realtion, next let P {INDEX_NO, LAST_NAME, FACULTY}, then P ( STUDENT) ={{138571, Klark, Law},{927502, Holl, Biology}, {714072, Lewis, Computer Science}, {965024, Barker, Mathematics}}

19
INDEX_NOFIRST_NAMELAST_NAMEYEARFACULTY 138571EvaKlark 2 Law 927502DavidHoll 1 Biology 714072AndrewLewis 3 Computer Science 965024CharlesBarker 1 Mathematics INDEX_NOLAST_NAMEFACULTY 138571KlarkLaw 927502HollBiology 714072LewisComputer Science 965024BarkerMathematics

20
The selection operator is used to produce a horizontal subset of a given relation by selecting only the tuples which meet the specified selection condition. Definition (Selection): Let I(R) be an instance of relation schema R={A 1,A 2,...,A n }, SC a selection condition (a boolean expression involving terms connected by logical connectives). The set SC (I(R)) := {r I(R); SC(r)=true} is called selection of I(R) on the basis of the SC condition.

21
Consider the following instance I(R) of R={A 1, A 2, A 3, A 4 }. I(R) The following instance is the selection of I(R) on the basis of the condition SC: (A 1 >A 2 and A 3 =A 4 ) {A1>A2 and A3=A4} (I(R)) A1A1 A2A2 A3A3 A4A4 52ax 119bb 63cy 2017dd A1A1 A2A2 A3A3 A4A4 119bb 2017dd

22
The join operator is applied to combine tuples from two or more relations. Definition (Joins): Let R and S be relation schemas such that [R S . The join of two relations I(R) and J(S) is defined as the ralation I(R) BC J(S):= {r T(R S); r[R] I(R) r[S] J(S)} If R=S then I(R) ) BC J(S) is equivalent to I(R) J(S).

23
Example (Join) Consider the following relation instances I(R) and J(S) of the schemas R={A,B,C,D,E} and S={A,B,F,G,H}, respectively. I(R) J(S) I(R) BC J(S) ABCDE 9hbxh 5oeko 12rimr 17tddt ABCDEFG 9hBxhnf tddtds ABCDEFG 9hbxhnf tddtds

24
A functional dependency defines a relationship between attributes of a given relation schema. Definition (Functional dependency) Let R={A 1, A 2,...,A n } be a relation schema and let X and Y be any subsets of R. We say that an attribute Y is functionally dependent on attribute X (X Y) if and only if (r, s I(R)) (r[X] = s[X] r[Y] = s[Y]). for any instance I(R) of the R schema. In particular, an instance J(R) of R satisfies a functional dependency X Y (X,Y R) if for any two tuples t and u of J(R), t[X] = u[X] t[Y] = u[Y]. Assume that a set of attributes X 1, X 2,...,X n functionally determines several attributes Y 1, Y 2,...,Y m : X 1 X 2...X n Y 1 X 1 X 2...X n Y 2 … X 1 X 2...X n Y m The above dependencies will be written as X 1 X 2...X n Y 1 Y 2...Y m.

25
Example Consider a relation schema COMPANY_CAR={VIN, NUMBER_PLATE, MARK, YEAR}. In COMPANY_CAR, for instance, attributes NUMBER_PLATE, MARK, and YEAR are functionally dependent on attribute VIN. These dependencies are represented as follows (in short VINNUMBER_PLATE MARK YEAR ): VINNUMBER_PLATE VINMARK VINYEAR The above dependencies hold for any instance of the COMPANY_CA R schema, in particular for the following instance called I(COMPANY_CAR) : VINNUMBER_PLATEMARKYEAR GTRE545WRTH256452EPA60PLFord Fusion I2003 THER186ACVG636853EL432PLOpel Corsa II2005 WDH144TETU063632EZG42PLCitroen C3 III2011

26
Note that the functional dependency MARKYEAR is also satisfied in I(COMPANY_CAR). However it does not hold for any instance of COMPANY_CAR. It is enough to consider the instance below to show that the condition occurring in the Definition does not hold: In other words, the sentence “cars having the same mark have the same production year” is not true in general case. VINnumber_platemarkyear GTRE545WRTH256452EPA60PLFord Fusion I2003 THER186ACVG636853EL432PLOpel Corsa II2005 WDH144TETU063632EZG42PLCitroen C3 III2011 YDAT45729683278503EL476PLCitroen C3 III2005

27
Let F be a subset of the set of all functional dependencies over a relation schema R, F:={X Y, X,Y R}. The set of all functional dependencies which can be derived from a given set F is called the closure of F, denoted as F +. The following rules, called Armstrong's axioms allow to construct the set F + (X,Y,Z R): 1. Y X X Y (reflexivity) 2. X Y X Z Y Z (augmentation) 3. X Y Y Z X Z (transitivity)

28
Introducing functional dependencies allows to extend the notion of a relation schema. Let A denote the previously defined relation schema R, A={A 1,A 2,...,A n } (each A i is assigned to the set of values D(A i )). Let F be a set of all functional dependencies defined on A, F={X Y, X,Y A}. The ordered pair R=(A,F) is called a relation schema.

29
Each relation schema R=(A,F) possesses a certain minimal subset of attributes whose values uniquely identify tuples of any instance of R. Such a subset of attributes is called a key (candidate key) for the schema. In other words, a subset K A is a key if and only if the following conditions hold There are no tuples of any instance of R which have the same values in K. No proper subset of K have unique identification property (key must be minimal). In the words case, a key can contain all the attributes of the given relation schema. Note that a schema can possess several keys. A primary key is one of all the keys selected by a database designer.

30
Example 2 Consider the relation schema COMPANY_CAR=(A,F) in which A={VIN, NUMBER_PLATE, MARK, YEAR}. To determine keys for COMPANY_CAR all its instances must be taken into account. The attributes VIN and NUMBER_PLATE always uniquely identify tuples occurring in any instance of the COMPANY_CAR schema. Besides there is no proper subset of these attributes which has unique identification property. The primary key for COMPANY_CAR is one of its keys.

31
A set of attributes of a given relation can points to a primary key in another relation. This set is called foreign key. The values inserted to a foreign key column must match the values stored in the primary key column of the reference relation. Example Relations and their keys (person_id is the primary key of Person, phone_id is the primary key of Phone, p_id is the foreign key of Phone which points to person_id.

32
Example Relations and their keys ( person_id is the primary key of PERSON, phone_id is the primary key of PHONE, p_id is the foreign key of PHONE which points to person_id. PERSON PHONE The p_id column can store only the values occurring in the column person_id of PERSON. person_ifirst_namelast_name 1EmilyOrman 2MartinLindsey 3AnthonyCain phone_idnumbertypep_id 5345-034-923M1 7582-532-572M3 11582-04-43S1

Similar presentations

OK

Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd (1923-2003) PhD from U. of Michigan, Ann Arbor Received Turing Award.

Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd (1923-2003) PhD from U. of Michigan, Ann Arbor Received Turing Award.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google

Ppt on emerging technologies in computer science Ppt on resources and development class 10 cbse Ppt on world environment day pictures A ppt on nanotechnology Ppt on chapter management of natural resources Ppt on prepaid energy meter Ppt online shopping project proposal Ppt online compressor sales Ppt on stone age tools Convert pptx file into ppt online