CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.

Slides:



Advertisements
Similar presentations
Chapter 3: Relational Model
Advertisements

CS 319: Theory of Databases: C4
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Relational Algebra Lecture 2. Relational Model Basic Notions Fundamental Relational Algebra Operations Additional Relational Algebra Operations Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Chapter 3: Relational Model
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Relational Algebra Lecture 2. Relational Model Basic Notions Fundamental Relational Algebra Operations Additional Relational Algebra Operations Extended.
SPRING 2004CENG 3521 E-R Diagram for the Banking Enterprise.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Model Database Management Systems I Alex Coman, Winter 2006.
Relational Model. 2 Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Chapter 6: Formal Relational Query Languages. 6.2 Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational.
1 The Relational Model By Elena Ciriani CS157A February 19, 2004 Professor Lee.
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
CS 370 Database Systems Lecture 11 Relational Algebra.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Mathematics and Computer Science San Jose State University.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Chapter 2: Relational Model II Relational Algebra basics Relational Algebra basics.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
Source: Database System Concepts, Silberschatz etc Edited: Wei-Pang Yang, IM.NDHU, Introduction to Database CHAPTER 2 RELATIONAL MODEL 2.1.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Midterm 2 Revision Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Database System Concepts, 5 th Ed. Bin Mu at Tongji University Chapter 2: Relational Model.
Computing & Information Sciences Kansas State University Wednesday, 03 Sep 2008CIS 560: Database System Concepts Lecture 3 of 42 Wednesday, 03 September.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
IS 230Lecture 7Slide 1 Relational Algebra Lecture 8 Text Book – Chapter.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Query Languages Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative “Pure”
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan Chapter 2: Relational Model.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
International Computer Institute, Izmir, Turkey Relational Model Asst.Prof.Dr.İlker Kocabaş UBİ502 at
Midlands State University Topic: Relational DB Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Relational Model
Lecture 4 of 42 Relational Joins Wednesday, 30 January 2008
Introduction to Database
Instructor: Mohamed Eltabakh
Chapter 2: Intro to Relational Model
Relational Algebra.
Chapter 2: Relational Model
Chapter 6: Formal Relational Query Languages
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Presentation transcript:

CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database

CIS552Relational Model2 Basic Structure Given sets A 1, A 2, …, A n a relation r is a subset of A 1  A 2  …  A n Thus a relation is a set of n-tuples (a 1, a 2, …, a n ) where a i  A i Example: If customer-name = {Jones, Smith, Curry, Lindsay} customer-street = {Main, North, Park} customer-city = { Harrison, Rye, Pittsfield} Then r = {(Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield)} is a relation over customer-name  customer-street  customer-city

CIS552Relational Model3 Relation Schema A 1, A 2, …, A n are attributes R = (A 1, A 2, …, A n ) is a relation schema Customer-schema = (customer-name, customer-street, customer-city) r(R) is a relation on the relation schema R customer (Customer-schema)

CIS552Relational Model4 Relation Instance The current values (relation instance) of a relation are specified by a table. An element t of r is a tuple; represented by a row in a table. customer

CIS552Relational Model5 Keys Let K  R K is a superkey of R if values for K are sufficient to uniquely identify a tuple of each possible relation r(R). By “possible r” we mean a relation r that could exist in the enterprise we are modeling. Example: {customer-name, customer-street} and {customer-name} are both superkey of customer, if no two customers can possibly have the same name. K is a candidate key if K is minimal Example: {customer-name} is a candidate key for Customer, since it is a superkey (assuming no two customers can possibly have the same name), and no subset of it is a superkey

CIS552Relational Model6 Determining Keys from E-R Sets Strong entity set. The primary key of the entity set becomes the primary key of the relation. Weak entity set. The primary key of the relation consists of the union of the primary key of the strong entity set and the discriminator of the weak entity set. Relationship set. The union of the primary keys of the related entity sets becomes a super key of the relation. For binary many-to-many relationship sets, above super key is also the primary key. For binary many-to-one relationship sets, the primary key of the “many” entity set becomes the relation’s primary key. For one-to-one relationship sets, the relation’s primary key can be that of either entity set.

CIS552Relational Model7 Query Languages Language in which user requests information form the database. Categories of languages: –Procedural –Non-procedural Formal languages: –Relational Algebra –Tuple Relational Calculus –Domain Relational Calculus Formal languages form underlying basis of query languages that people use.

CIS552Relational Model8 Relational Algebra Procedural language Six basic operators –select –project –union –set difference –cartesian product –rename The operators take two or more relations as inputs and give a new relation as a result.

CIS552Relational Model9 Select Operation Notation  p (r) Defined as:  p (r) = {t | t  r and p(t)} where P is a formula in propositional calculus, dealing with terms of the form: attribute  attribute or constant      connected by:  (and),  (or),  (not)

CIS552Relational Model10 Select Operation - Example Relation r:  A=B  D > 5 (r)

CIS552Relational Model11 Project Operation Notation:  A 1, A 2, …, A k (r) where A 1, A 2 are attributes and r is a relation. The result is defined as the relation of k columns obtained by erasing the columns that are not listed Duplicate rows are removed from result, since relations are sets

CIS552Relational Model12 Project Operation - Example Relation r:  A, C (r) =

CIS552Relational Model13 Union Operation Notation: r  s Defined as: r  s = { t | t  r or t  s} For r  s to be valid, 1. r, s must have the same arity (same number of attributes) 2. The attribute domains must be compatible (e.g. 2nd column of r deals with the same type of values as does the 2nd column of s)

CIS552Relational Model14 Union Operation - Example Relations r, s: r  s

CIS552Relational Model15 Set Difference Operation Notation: r - s Defined as: r - s = { t | t  r and t  s} Set differences must be taken between compatible relations. –r and s must have the same arity –attribute domains of r and s must be compatible

CIS552Relational Model16 Set Difference Operation - Example

CIS552Relational Model17 Cartesian-Product Operation Notation: r  s Defined as: r  s = { tq | t  r and q  s} Assume that attributes of r(R) and s(S) are disjoint. (That is, R  S =  ). If attributes of r(R) and s(S) are not disjoint, then renaming must be used.

CIS552Relational Model18 Cartesian-Product Operation - Example

CIS552Relational Model19 Banking Tables

CIS552Relational Model20 Customer  Borrower

CIS552Relational Model21 Customer  Borrower

CIS552Relational Model22 Composition of Operations Can build expressions using multiple operations Example:  A= C (r  s) Natural Join –Notation: r s –Let r and s be relations on schemas R and S respectively. The result is a relation on schema R  S which is obtained by considering each pair of tuples t r from r and t s from s. –If t r and t s have the same value on each of the attributes in R  S, a tuple t is added to the result, where t has the same values as t r on the attributes in R t has the same values as t s on the attributes in S

CIS552Relational Model23 Composition of Operations (Cont.) Example: R = (A, B, C, D) S = (E, B, D) Result schema = (A, B, C, D, E) r s is defined as:  r.A,r.B,r.C,r.D,s.E (  r.B = s.B  r.D = s.D ( r  s ) )

CIS552Relational Model24 Natural Join Operation - Example

CIS552Relational Model25 Division Operation r  s Suited to queries that include the phrase “for all”. Let r and s be relations on schemas R and S respectively, where: R = (A 1, …, A m, B 1, …, B n ) S = (B 1, …, B n ) The result of r  s is a relation on schema: R - S = (A 1, …, A m ) r  s = { t | t  R-S (r)   u  s (tu  r) }

CIS552Relational Model26 Division Operation (Cont.) Property  Let q = r  s  Then q is the largest relation satisfying: q  s  r Definition in terms of the basic algebra operation Let r(R) and s(S) be relations, and let S  R r  s =  R-S (r)   R-S ( (  R-S (r)  s)   R-S,S (r) ) To see why:   R-S,S (r) simply reorders attributes of r   R-S ((  R-S (r)  s)   R-S,S (r)) gives those tuples t in  R-S (r) such that for some tuple u  s, tu  r.

CIS552Relational Model27 Division Operation - Example = 

CIS552Relational Model28 Another Division Example = 

CIS552Relational Model29 Assignment Operation The assignment operation (  ) provides a convenient way to express complex queries; write query as a sequential program consisting of a series of assignments followed by an expression whose value is displayed as the result of the query. Assignment must always be made to a temporary relation variable. Example: Write r  s as temp1   R-S (r) temp2   R-S ((temp1  s)   R-S,S (r)) result = temp1  temp2 –The result to the right of the  is assigned to the relation variable on the left of the . –May use variable in subsequent expressions

CIS552Relational Model30 Example Queries Find those customers who have an account from at least the “Downtown” and “Updown” branches. Query 1  cn (  bn = “Downtown” ( depositor account ))   cn (  bn = “Uptown” ( depositor account )) where cn denotes customer-name and bn denotes branch-name Query 2  cn, bn (depositor account ))   temp(bn) ( {(“Downtown”), (“Uptown”)} )

CIS552Relational Model31 Example Queries (2) Find those customers who have accounts at all branches located in Brooklyn.  customer-name, branch-name (depositor account ))   branch-name (  branch-city = “Brooklyn” ( branch ))

CIS552Relational Model32 Sample Problems Consider the following relational schema: Flights (flno, from, to, distance, departs) Aircraft (aid, aname, range) Certified (eid, aid) Employees (eid, ename, salary) By definition, pilots are those employees who are certified on at least one aircraft. An aircraft can be used for any flight provided it has sufficient range. Pilots can pilot any flight provided they are certified on an aircraft with sufficient range.

CIS552Relational Model33 Sample Problems (cont.) 1. Find eid’s of pilots who are certified on some Boeing. 2. Find names of pilots who are certified on some Boeing. 3. Find aid’s of aircraft that can fly non-stop from LA to NY. 4. Find flno of flights that can be piloted by every pilot whose salary is over $100, Solve problem 4 without using the division operator. 6. Find names of pilots who can operate planes with a range greater than 3,000 miles, but are not certified on any Boeing. 7. Find eid of employee(s) with the highest salary. 8. Find eid of employee(s) with the second highest salary. 9. Find eid of employee(s) certified on the most aircraft. 10. Find eid’s of employees certified on exactly three aircraft.