Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model I (based on notes by Silberchatz,Korth, and Sudarshan.

Slides:



Advertisements
Similar presentations
CS 319: Theory of Databases: C4
Advertisements

CMU SCS Carnegie Mellon Univ. School of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture#6: Rel. model - SQL part1 (R&G, chapter.
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
©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.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Query by example (based on notes by Silberchatz,Korth, and Sudarshan.
Chapter 3: Relational Model
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
CS 405G: Introduction to Database Systems Lecture 4: Relational Model Instructor: Chen Qian.
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.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model – SQL Part I (based on notes by Silberchatz,Korth,
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model III (based on notes by Silberchatz,Korth, and.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
1 Session 3 Welcome: To session 3- the first learning sequence “ Introduction to Relational Model“ Recap : In the previous learning sequences, we discussed.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model – SQL Part II (based on notes by Silberchatz,Korth,
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
A Free sample background from © 2006 By Default! R.SARAVANA KUMAR S.NAVEEN Relational Database Model.
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
©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.
CSc340 1b1 The Relational Model Chapter 2 Database Schema Keys Schema Diagrams Relational Query Languages Relational Operations.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 2: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational model.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
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)
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational domain calculus.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 – DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus.
Database System Concepts, 5 th Ed. Bin Mu at Tongji University Chapter 2: Relational Model.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Relational Model – SQL (based on notes by Silberchatz,Korth, and.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational tuple calculus.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Temple University – CIS Dept. CIS616– Principles of Database Systems V. Megalooikonomou Relational Model (based on notes by Silberchatz,Korth, and Sudarshan.
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, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan Chapter 2: Relational Model.
Midlands State University Topic: Relational DB Model
Introduction to Relational Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Intro to Relational Model
Chapter 3: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Lecture #4: Relational Algebra
Chapter 2: Relational Model
Relational Model.
Chapter 2: Intro to Relational Model
Chapter 2: Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Presentation transcript:

Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model I (based on notes by Silberchatz,Korth, and Sudarshan and notes by C. Faloutsos at CMU)

Overview history concepts Formal query languages relational algebra rel. tuple calculus rel. domain calculus

History before: records, pointers, sets etc introduced by E.F. Codd ( ) in 1970 revolutionary!!! first systems: (System R; Ingres) Turing award in 1981

Concepts Database: a set of relations (= tables) rows: tuples columns: attributes (or keys) superkey, candidate key, primary key

Example Database:

Example: cont’d Database: rel. schema (attr+domains) tuple k-th attribute (Dk domain)

Example: cont’d rel. schema (attr+domains) instance

Example: cont’d rel. schema (attr+domains) instance Di: the domain of the I-th attribute (eg., char(10) Formally: an instance is a subset of (D1 x D2 x …x Dn)

Example: cont’d superkey (eg., ‘ssn, name’): determines record cand. key (eg., ‘ssn’, or ‘st#’): minimal superkey (no subset of it is a superkey) primary key: one of the cand. keys

Another example 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 x Customer-street x Customer-city

Relations, tuples Relation Schema: A 1, A 2, …, A n are attributes R = (A 1, A 2, …, A n ) is a relation schema E.g. Customer-schema = (customer-name, customer-street, customer-city) r(R) is a relation on the relation schema R E.g.customer (Customer-schema) Relations are unordered Order of tuples is irrelevant (tuples may be stored in an arbitrary order)

Database A database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part of the information E.g.: account : stores information about accounts depositor : stores information about which customer owns which account customer : stores information about customers Storing all information as a single relation such as bank(account-number, balance, customer-name,..) results in repetition of information (e.g. two customers own an account) the need for null values (e.g. represent a customer without an account) Normalization theory (discuss later) deals with how to design relational schemas

Overview history concepts Formal query languages relational algebra rel. tuple calculus rel. domain calculus

Formal query languages How do we collect information? Eg., find ssn’s of people in cis331 (recall: everything is a set!) One solution: Relational algebra, i.e., set operators (procedural language) Q1: Which operators?? Q2: What is a minimal set of operators?

. set union U set difference ‘-’ Relational operators

Example: Q: find all students (part or full time) A: PT-STUDENT union FT-STUDENT

Observations: two tables are ‘union compatible’ if they have the same attributes (i.e., same arity: number of attributes and same ‘domains’) Q: how about intersection ? U

Observations: A: redundant: STUDENT intersection STAFF = STUDENT - (STUDENT - STAFF) STUDENT STAFF

. set union set difference ‘-’ Relational operators U

Other operators? E.g., find all students on ‘Main street’ A: ‘selection’

Other operators? Notice: selection (and rest of operators) expect tables, and produce tables --> can be cascaded!! For selection, in general:

Selection - examples Find all ‘Smiths’ on ‘Forbes Ave’ ‘condition’ can be any boolean combination of ‘=‘, ‘>’, ‘>=‘,...

selection. set union set difference R - S Relational operators R U S

selection picks rows - how about columns? A: ‘projection’ - eg.: finds all the ‘ssn’ - removing duplicates Relational operators

Cascading: ‘find ssn of students on ‘forbes ave’ Relational operators

selection projection. set union set difference R - S Relational operators R U S

Are we done yet? Q: Give a query we can not answer yet! Relational operators

A: any query across two or more tables, eg., ‘find names of students in cis351’ Q: what extra operator do we need?? A: surprisingly, the cartesian product is enough! Relational operators TAKES SSNc-idgrade 123cis331A 234cis331B

Cartesian product E.g., dog-breeding: MALE x FEMALE gives all possible couples x =

so what? Eg., how do we find names of students taking cis351? TAKES SSNc-idgrade 123cis331A 234cis331B

Cartesian product A: SsnNameAddressssncidgrade 123smithmain str123cis331A 234jonesforbes ave123cis331A 123smithmain str234cis331B 234jonesforbes ave234cis331B

Cartesian product SsnNameAddressssncidgrade 123smithmain str123cis331A 234jonesforbes ave123cis331A 123smithmain str234cis331B 234jonesforbes ave234cis331B

SsnNameAddressssncidgrade 123smithmain str123cis331A 234jonesforbes ave123cis331A 123smithmain str234cis331B 234jonesforbes ave234cis331B

selection projection cartesian product MALE x FEMALE set union set difference R - S FUNDAMENTAL Relational operators R U S

Relational ops Surprisingly, they are enough, to help us answer almost any query we want!! derived operators, for convenience set intersection join (theta join, equi-join, natural join) ‘rename’ operator division

Joins Equijoin:

Cartesian product A: SsnNameAddressssncidgrade 123smithmain str123cis331A 234jonesforbes ave123cis331A 123smithmain str234cis331B 234jonesforbes ave234cis331B

Joins Equijoin: theta-joins: generalization of equi-join - any condition

Joins very popular: natural join: R S like equi-join, but it drops duplicate columns: STUDENT(ssn, name, address) TAKES(ssn, cid, grade)

Joins nat. join has 5 attributes SsnNameAddressssncidgrade 123smithmain str123cis331A 234jonesforbes ave123cis331A 123smithmain str234cis331B 234jonesforbes ave234cis331B equi-join: 6

Natural Joins - nit-picking if no attributes in common between R, S: nat. join -> cartesian product:

Overview - rel. algebra fundamental operators derived operators joins etc rename division examples

rename op. Q: why? A: Shorthand (BEFORE can be a relational algebra expression) self-joins; … for example, find the grand-parents of ‘Tom’, given PC(parent-id, child-id)

rename op. PC(parent-id, child-id)

rename op. first, WRONG attempt: (why? how many columns?) Second WRONG attempt:

rename op. we clearly need two different names for the same table - hence, the ‘rename’ op.

Overview - rel. algebra fundamental operators derived operators joins etc rename division examples

Division Rarely used, but powerful. Suited for queries that include the phrase “for all” Example: find suspicious suppliers, i.e., suppliers that supplied all the parts in A_BOMB

Division

Observations: ~reverse of cartesian product It can be derived from the 5 fundamental operators (!!) How?

Division Answer: gives those tuples t in such that for some tuple u in S, tu not in R.

Overview - rel. algebra fundamental operators derived operators joins etc rename division examples

Sample schema CLASS c-idc-nameunits cis331d.b.2 cis321o.s.2 TAKES SSNc-idgrade 123cis331A 234cis331B find names of students that take cis351

Examples find names of students that take cis351

Sample schema find course names of ‘smith’ CLASS c-idc-nameunits cis331d.b.2 cis321o.s.2 TAKES SSNc-idgrade 123cis331A 234cis331B

Examples find course names of ‘smith’

Examples find ssn of ‘overworked’ students, ie., that take cis331, cis342, cis350

Examples find ssn of ‘overworked’ students, ie., that take cis331, cis342, cis350: almost correct answer: )( )( )( TAKES namec c c        

Examples find ssn of ‘overworked’ students, ie., that take cis331, cis342, cis350 - Correct answer: )]([ ([ ([ TAKES namecssn namecssn namecssn        

Examples find ssn of students that work at least as hard as ssn=123 (ie., they take all the courses of ssn=123, and maybe more)

Sample schema CLASS c-idc-nameunits cis331d.b.2 cis321o.s.2 TAKES SSNc-idgrade 123cis331A 234cis331B

Examples find ssn of students that work at least as hard as ssn=123 (ie., they take all the courses of ssn=123, and maybe more

Conclusions Relational model: only tables (‘relations’) relational algebra: powerful, minimal: 5 operators can handle almost any query! most non-trivial op.: join

The bank database