Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.

Similar presentations


Presentation on theme: "ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model."— Presentation transcript:

1 ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model Fundamentals ©Manuel Rodriguez – All rights reserved

2 ICOM 6005Dr. Manuel Rodriguez Martinez2 Readings Read –Chapter 2 of old version of textbook –Chapter 3 of new version of texbook –Paper by E.F. Codd A Relational Model of Data for Large Shared Data Banks Get: –ICOM6005-Manual #1 – from Engineering Reproduction Center

3 ICOM 6005Dr. Manuel Rodriguez Martinez3 On Sets and Relations A set S is a collection of objects, where there are no duplicates –Examples A = {a, b, c} B = {0, 2, 4, 6, 8} C = {Jose, Pedro, Ana, Luis} The objects that are part of a set S are called the elements of the set. –Notation: 0 is an element of set B is written as 0  B. 3 is not an element of set B is written as 3  B.

4 ICOM 6005Dr. Manuel Rodriguez Martinez4 Cardinality of Sets Sets might have –0 elements – called the empty set . –1 elements – called a singleton –N elements – a set of N elements (called a finite set) Ex: S = {car, plane, bike} –  elements – an infinite number of elements (called infinite set) Integers, Real, Even numbers: E = {0, 2, 4, 6, 8, 10, …} –Dot notation means infinite number of elements The cardinality of a set is its number of elements –Notation: cardinality of S is denoted by |S| –Could be an integer number or infinity symbol .

5 ICOM 6005Dr. Manuel Rodriguez Martinez5 Cardinality of Sets (cont.) Some examples: –A = {a,b,c} |A| = 3 –R – set of real numbers |R| =  –E = {0, 2, 4, 6, 8, 10, …} |E| =  –  the empty set |  | = 0

6 ICOM 6005Dr. Manuel Rodriguez Martinez6 Set notations and equality of Sets Enumeration of elements of set S –A = {a,b c} –E = {0, 2, 4, 6, 8, 10, …} Enumeration of the properties of the elements in S –E = {x : x is an even integer} –E = {x: x  I and x%2=0, where I is the set of integers.} Two sets are said to be equal if and if only they both have the same elements –A = {a, b, c}, B = {a, b, c}, then A = B –if C = {a, b, c, d}, then A  C Because d  A

7 ICOM 6005Dr. Manuel Rodriguez Martinez7 Sets and Subsets Let A and B be two sets. B is said to be a subsets of A if and only if every member x of B is also a member of A –Notation: B  A –Examples: A = {1, 2, 3, 4, 5, 6}, B = {1, 2}, then B  A D = {a, e, i, o, u}, F = {a, e, i, o, u}, then F  D –If B is a subset of A, and B  A, then we call B a proper subset Notation: B  A A = {1, 2, 3, 4, 5, 6}, B = {1, 2}, then B  A –The empty set  is a subset of every set, including itself   A, for every set A –If B is not a subset of A, then we write B  A

8 ICOM 6005Dr. Manuel Rodriguez Martinez8 Set Union Let A and B be two sets. Then, the union of A and B, denoted by A  B is the set of all elements x such that either x  A or x  B. –A  B = {x: x  A or x  B} Examples: –A = {10, 20, 30, 40, 100}, B = {1,2, 10, 20} then A  B = {1, 2, 10, 20, 30, 40, 100} –C = {Tom, Bob, Pete}, then C   = C –For every set A, A  A = A

9 ICOM 6005Dr. Manuel Rodriguez Martinez9 Set Intersection Let A and B be two sets. Then, the intersection of A and B, denoted by A  B is the set of all elements x such that x  A and x  B. –A  B = {x: x  A and x  B} Examples: –A = {10, 20, 30, 40, 100}, B = {1,2, 10, 20} then A  B = {10, 20} –Y = {red, blue, green, black}, X = {black, white}, then Y  X = {black} –E = {1, 2, 3}, M={a, b} then, E  M =  –C = {Tom, Bob, Pete}, then C   =  For every set A, A  A = A Sets A and B disjoint if and only if A  B =  –They have nothing in common

10 ICOM 6005Dr. Manuel Rodriguez Martinez10 Set Difference Let A and B be two sets. Then, the difference between A and B, denoted by A - B is the set of all elements x such that x  A and x  B. –A - B = {x: x  A and x  B} Examples: –A = {10, 20, 30, 40, 100}, B = {1,2, 10, 20} then A - B = {30, 40, 100} –Y = {red, blue, green, black}, X = {black, white}, then Y - X = {red, blue, green} –E = {1, 2, 3}, M={a, b} then, E - M = E –C = {Tom, Bob, Pete}, then C -  = C –For every set A, A - A = 

11 ICOM 6005Dr. Manuel Rodriguez Martinez11 Power Set and Partitions Power Set: Given a set A, then the set of all possible subsets of A is called the power set of A. –Notation: –Example: A = {a, b, 1} then = { , {a}, {b}, {1}, {a,b}, {a,1}, {b,1}, {a,b,1}} Note: empty set is a subset of every set. Partition: A partition  of a nonempty set A is a subset of such that –Each set element P   is not empty –For D, F  , D  F, it holds that D  F =  –The union of all P   is equal to A. –Example: A = {a, b, c}, then  = {{a,b}, {c}}. Also  = {{a}, {b}, {c}}. But this is not: M = {{a, b}, {b}, {c}}

12 ICOM 6005Dr. Manuel Rodriguez Martinez12 Cartesian Products and Relations Cartesian product: Given two sets A and B, the Cartesian product between and A and, denoted by A x B, is the set of all ordered pairs (a,b) such a  A and b  B. –Formally: A x B = {(a,b): a  A and b  B} –Example: A = {1, 2}, B = {a, b}, then A x B = {(1,a), (1,b), (2,a), (2,b)}. A binary relation R on two sets A and B is a subset of A x B. –Example: A = {1, 2}, B = {a, b}, then A x B = {(1,a), (1,b), (2,a), (2,b)}, and one possible R  A x B = {(1,a), (2,a)}

13 ICOM 6005Dr. Manuel Rodriguez Martinez13 N-ary Relations Let A1, A2, …, An be n sets, not necessarily distinct, then an n-ary relation R on A1, A2, …, An is a sub- set of A1 x A2 x … x An. –Formally: R  A1 x A2 x … x An –R = {(a1, a2, …,an) : a1  A1 and a2  A2 and … and an  An} –Example: R = set of all real numbers R x R x R = three-dimensional space P = {(x, y, z): x  R and x  0 and y  R and y  0 and y  R and y  0} = Set of all three-dimensional points that have positive coordinates

14 ICOM 6005Dr. Manuel Rodriguez Martinez14 The Relational Model of Data id nameageaddress 123Bob19San Juan 45678Tim53New York 100971Mary25Miami Representing information about customers for a store. Data is viewed in tabular form This is equivalent to a relation

15 ICOM 6005Dr. Manuel Rodriguez Martinez15 The Relational Model of Data Proposed in 1970 by E.F. Codd Models a data set as a table –Each column represent a value –Each row represents a group of values that represent a relationship. This relationship describes a given entity. Thus every row in a table describes an entity. –Columns are often called attributes because they describe information about the entity described in the row. –Rows are often called records. –Rows are also called tuples, because they are elements in a relation formed by the set of attributes associated with the table.

16 ICOM 6005Dr. Manuel Rodriguez Martinez16 Formal Model Let A1, A2, …, An be sets of attributes, then a relation R is a subset of A1 x A2 x … x An –R  A1 x A2 x A3 x … x An –Each Ai is called a domain of the relation –Each element r of R is called a n-tuple or simply a tuple –Each r in R is of the form (a1, a2, …,an) where a1  A1, a2  A2, …, an  An. Each relation has a: –relational schema Definition of the structure of the relation R –Relational instance A set of tuples that form a case of the relation under the defined schema

17 ICOM 6005Dr. Manuel Rodriguez Martinez17 Relation Schema Describes the name and columns in a relation Components of the schema: –Relation name –Name of each attribute (also called column or field) –Domain of each attribute Described by domain name (often type name) and values. Example: –costumers(id:string, name:string,age:integer,address:string); Name: costumers Attributes: id, name, age, address Domains: strings and integers

18 ICOM 6005Dr. Manuel Rodriguez Martinez18 Relation Instance A set of tuples (records) in which each tuple has the same number of attributes as in the schema. Example: –Schema costumers(id:string, name:string,age:integer,address:string); –Instance of Customer id nameageaddress 123Bob19San Juan 45678Tim53New York 100971Mary25Miami

19 ICOM 6005Dr. Manuel Rodriguez Martinez19 Relation cardinality and degree Cardinality – number of tuples in the relation R Degree – number of attributes in the relation R. Also called the arity of the relation R. Example: –cardinality = 3, degree = 4 id nameageaddress 123Bob19San Juan 45678Tim53New York 100971Mary25Miami

20 ICOM 6005Dr. Manuel Rodriguez Martinez20 Keys on a relation superkey – a set of one or more attributes that uniquely identify a tuple r in a relation R. –Minimal superkey – a key from which if we remove an attribute X, it would no longer be a superkey. candidate keys – set of all minimal superkeys in a relation R. primary key – a candidate key that the database designer chooses as the means to identify the tuples in a relation R.

21 ICOM 6005Dr. Manuel Rodriguez Martinez21 Examples of keys –Super keys: {id,name}, {id, name, address} –candidate key: {id} –primary key: {id} id nameageaddress 123Bob19San Juan 45678Tim53New York 1253Joe19Los Angeles 37322Bob30San Juan 100971Mary25Miami


Download ppt "ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model."

Similar presentations


Ads by Google