Domains, Relations & Base RelVars (Ch

Slides:



Advertisements
Similar presentations
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Advertisements

Database Languages Chapter 7. The Relational Algebra.
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
Relations The Relational Data Model John Sieg, UMass Lowell.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Chapter 6 Relations. Topics in this Chapter Tuples Relation Types Relation Values Relation Variables SQL Facilities.
Databases Illuminated
Concepts of Database Management, Fifth Edition
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Chapter 4 The Relational Model.
Relational Algebra II. Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
3-1 Unit 3 The Relational Model. 3-2 Wei-Pang Yang, Information Management, NDHU Outline  3.1 Introduction  3.2 Relational Data Structure  3.3 Relational.
Relational Algebra - Chapter (7th ed )
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
Data Integrity An empty database is a correct database.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
Bayu Adhi Tama, ST., MTI. Introduction Relational algebra and relational calculus are formal languages associated with the relational.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Advanced Relational Algebra & SQL (Part1 )
SQL - miscellaneous D. Christozov / G.Tuparov INF 280 Database Systems: SQL – miscellaneous 1.
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
1 Announcements Reading for next week: Chapter 4 Your first homework will be assigned as soon as your database accounts have been set up.  Expect an .
Relational Algebra Prof. Yin-Fu Huang CSIE, NYUST Chapter 7.
Relations Prof. Yin-Fu Huang CSIE, NYUST Chapter 6.
Types Prof. Yin-Fu Huang CSIE, NYUST Chapter 5. Advanced Database SystemYin-Fu Huang Relation, tuple, cardinality, attribute, degree, domain, primary.
Integrity Prof. Yin-Fu Huang CSIE, NYUST Chapter 9.
Views Prof. Yin-Fu Huang CSIE, NYUST Chapter 10. Advanced Database System Yin-Fu Huang 10.1Introduction Example: Var Good_Supplier View (S Where Status.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
More SQL: Complex Queries, Triggers, Views, and Schema Modification
COMP3017 Advanced Databases
Relational Algebra Chapter 4 1.
Lecture 2 The Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 8 Relational Calculus.
Relational Algebra Chapter 4, Part A
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Relational Algebra Chapter 4 1.
The Relational Algebra and Relational Calculus
Relational Algebra Chapter 4 - part I.
Instructor: Mohamed Eltabakh
Φροντιστήριο SQL (από το βιβλίο του Date)
The Relational Model Textbook /7/2018.
Advanced Database System
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
STRUCTURE OF PRESENTATION :
STRUCTURE OF PRESENTATION :
Relational Algebra Chapter 4 - part I.
Chapter 4 Relational Algebra
Presentation transcript:

Domains, Relations & Base RelVars (Ch Domains, Relations & Base RelVars (Ch. 5 Overview) Relational Algebra & Calculus,, & SQL (Ch. 6,7) Preview – Design Issues & Integrity Constraints (Ch.8) A Design Review Ch. 5? Each attribute implies a domain (data type, set of values) Types do not imply physical representation (encap…) But at least one possible physical representation is suggested Specific data types are orthogonal to the relational model. Scalar types have visible components (non-scalars don’t). The relational model is strongly typed. Some operators ( selector = < > := CAST AS )

A table is a concrete representation of a relation. Relations & RelVars Relations (relation values) A table is a concrete representation of a relation. Tuple – a set of ordered pairs, no duplicates, unordered. Relations have cardinality & degree. RelVars & Views define relations The system catalog maintains the relvars. SQL is used to create RelVars – CREATE DOMAIN, CREATE TABLE Relations – INSERT, DELETE, UPDATE (tuples)

J.CITY = P.CITY JNAME | | PNAME QTY * 100 QTY + 100 STATUS = 5 Type Checking J.CITY = P.CITY JNAME | | PNAME QTY * 100 QTY + 100 STATUS = 5 J.CITY < S.CITY COLOR = P.CITY J.CITY = P.CITY | | ‘burg’

Operates on relations, gives relations as results Relational Algebra Operates on relations, gives relations as results Restrict (Select)  -- subset of tuples Project  -- subset of columns Product -- all possible combinations of two tuples A X A Y B X B Y A B X Y (Natural) Join: connecting tuples based on common value in same-named columns A1 B1 A2 B1 A3 B2 B1 C1 B2 C2 B3 C3 A1 B1 C1 A2 B1 C1 A3 B2 C2

Other Joins Theta Join -- join two relations but not on the equality operation ((S RENAME CITY AS SCITY) TIMES (P RENAME CITY AS PCITY) ) WHERE SCITY > PCITY Semi Join -- (natural) join two relations, but return only attributes of the first ((S SEMIJOIN (SP WHERE P# = # (‘P2’))

Standard Set Operations Union, Intersection, Difference treat relations as sets of tuples old_ext(inv# ext) 13 1118 13 1119 14 3443 16 3439 rings_at(inv# ext) 12 1118 13 1118 13 1120 14 3400 14 3443 15 3443 16 3439 (inv# ext) (inv# ext) (inv# ext)

Given 2 unary and 1 binary relation -- Division Given 2 unary and 1 binary relation -- find tuples in the (first) unary relation matched in the binary relation -- w/ tuples in the other unary relation A X A Y A Z B X C Y A B C X Z A

Analogy Division a  b is the largest q such that b * q  a phone_bk(person ext) Randall 2116 Ross 2116 Ricard 2116 Randall 2218 Ross 2218 Rivers 2218 Ross 3972 Ricard 3972 Rivers 3972  r(ext) 2116 2118 = (person) Randall Ross  s(person) Ross Ricard = (ext) 2116 3972 Analogy a  b is the largest q such that b * q  a

Associative & Commutative -- UNION, INTERSECTION, TIMES, JOIN Properties & Examples Associative & Commutative -- UNION, INTERSECTION, TIMES, JOIN ((SP JOIN S) WHERE P# = P# (‘P2’)) {SNAME} (((P WHERE COLOR = COLOR (‘Red’)) JOIN SP) {S#} JOIN S) {SNAME} ((S {S#} DIVIDEBY P {P#} PER SP {S#, P#}) JOIN S {SNAME} S{S#} DIVIDEBY (SP WHERE S# = S# (‘S2’)) {P#} PER SP {S#,P#} (((S RENAME S# AS SA) {SA, CITY} JOIN (S RENAME S# AS SB) {SB, CITY} ) WHERE SA < SB) {SA,SB}

the Algebra enables writing relational expressions Retrieval Update Integrity constraints Derived relvars (views) Stability requirements (concurrency control) Security constraints (scope of authorization) Transformation rules -> OPTIMIZATION ((SP JOIN S) WHERE P# = P# (‘P2’)) {SNAME} ((SP WHERE P# = P# (‘P2’)) JOIN S) {SNAME}

Aggregates -- COUNT, SUM, AVG, MAX, MIN, ALL, ANY Miscellaneous Aggregates -- COUNT, SUM, AVG, MAX, MIN, ALL, ANY SUMMARIZE SP PER SP {P#} ADD SUM (QTY) AS TOTQTY SUMMARIZE (P JOIN SP) PER P {CITY} ADD COUNT AS NSP Relational Comparisons = equals /= not equals <= subset of (IN) < proper subset of >= superset > proper superset IS_EMPTY GROUP, UNGROUP

The algebra - a language to describe how to construct a new relation. Relational Calculus The algebra - a language to describe how to construct a new relation. The calculus - a language to write a definition of that new relation. FORALL PX (PX.COLOR = COLOR (‘Red’)) EXISTS SPX (SX.S# = SX.S# AND SPX.P# = P# (‘P2’) Procedural vs. Non-procedural Relational Completeness

6.13 Get full details of all projects. JX SELECT * FROM J 6.15 Get supplier numbers for suppliers who supply project J1. ( SPJ WHERE J# = J# (‘J1’) ) {S#} SPJX.S# WHERE SPJX.J# = J# (‘J1’) SELECT DISTINCT SPJ.S# FROM SPJ WHERE SPJ.J# = ‘J1’ 6.18 Get supplier-number/part-number/project-number triples such that supplier part and project are all colocated). (S JOIN P JOIN J) {S#, P#, J#} (SX.S#, PX.P#, JX.J# ) WHERE SX.CITY = PX.CITY AND PX.CITY = JX.CITY AND JX.CITY = SX.CITY SELECT S.S#, P.P#, J.J# FROM S,P,J WHERE S.CITY = P.CITY AND P.CITY = J.CITY. Query Exercises

An attribute value must match its type. A primary key must be unique. Integrity Preview! An attribute value must match its type. A primary key must be unique. A tuple’s foreign key must be of the same type as its “matching” primary key. To create a record with a given foreign key, a record in the corresponding table must have that value as its primary key. Many to many relationships cannot be modeled (directly). Find examples to support these in SPJ!

Study Questions Which of the relational algebra, tuple calculus and domain calculus is SQL based on? Can any relational query be expressed in a single SQL statement? To what extent do these query languages go beyond the relational model? Why might QueryByExample languages be easier to use than SQL for someone unfamiliar with the database scheme of a database?

Lab Assignment for Next Week With your partner, finish creating and populating the SPJ database. Run the assigned queries from Chapter 6. SQL BNF http:// cuiwww.unige.ch/~falquet/sdbd/langage/SQL92/BNFindex.html