9th December 2014Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.

Slides:



Advertisements
Similar presentations
Data Bits Many to Many Subkeys JoinsQueries Attributes $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 Final DataBit.
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
Introduction to Database Systems 1 Relational Algebra Relational Model: Topic 3.
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus University of California, Berkeley School of Information Management.
Database Systems Lecture 5 Natasha Alechina
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 8: Relations Relations(8.1) n-any Relations &
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Retrievals & Projections Objectives of the Lecture : To consider retrieval actions from a DB; To consider using relational algebra for defining relations;
Introduction to Computer Systems
Concepts of Database Management Seventh Edition
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
University of Sunderland COM 220Lecture Two Slide 1 Database Theory.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
6 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
6 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
6.1 © 2010 by Prentice Hall 6 Chapter Foundations of Business Intelligence: Databases and Information Management.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Chapter 7: Relations Relations(7.1) Relations(7.1) n-any Relations & their Applications (7.2) n-any Relations & their Applications (7.2)
4a. Structured Query Language - SELECT Statement Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Set Operations Objectives of the Lecture : To consider the Set Operations Union, Difference and Intersect; To consider how to use the Set Operations in.
29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Department of Computer Science and Information Systems Autumn 2015 Preliminary.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
29 September 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Texas State Technical College DISCOVER! Cartesian Product Cover all the bases.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems
10 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
20 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
13 October 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Dec. 13, 2002 WISE2002 Processing XML View Queries Including User-defined Foreign Functions on Relational Databases Yoshiharu Ishikawa Jun Kawada Hiroyuki.
3 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
17 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
SQL.. AN OVERVIEW lecture3 1. Overview of SQL 2  Query: allow questions to be asked of the data and display only the information required. It can include.
1st December 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Lectures 2&3: Introduction to SQL. Lecture 2: SQL Part I Lecture 2.
Introduction to Computer Systems
24 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
27 October 2015 Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
4 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Databases Databases are collections of information; our study repeats a theme: Tell the computer the structure, and it can help you! © 2004, Lawrence Snyder.
Introduction to Computer Systems
Database Systems (資料庫系統)
, MS-Access, QBE, Access/Oracle
Introduction to Programming
CSE 504 Discrete Structures & Foundations of Computer Science
Structured Query Language (SQL) William Klingelsmith
Database Systems 10/13/2010 Lecture #4.
Introduction to Programming
Chapter 9: Database Systems
SQL .. An overview lecture3.
Introduction to Programming
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Database SQL.
Introduction to Programming
Presentation transcript:

9th December 2014Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems Autumn 2014 Week 11a: Relational Operations

9th December 2014Brookshear, Section 9.22 Database Queries Show all orders for plate. Show all order numbers and the associated products. Show all order numbers and the associated company names. In the relational model the answers are always relations, ie. tables. Can the answers to database queries be found in a systematic way?

9th December 2014Brookshear, Section 9.23 Relational Operations The answers to database queries are obtained using the relational operations SELECT PROJECT JOIN These operations produce new relations from old ones.

9th December 2014Birkbeck College4 Relational Database 37102£ Plate 43103£ Case 2054£ Panel 102Sperry1 The Lane 103Univac15 Retail Road 54Honeywell205 North Street NumCNumPriceDue date Product OC NumNameAddress O: relation containing orders C: relation containing details of customers

9th December 2014Brookshear, Section 9.25 List of Tuples of Orders for Plate 37102£ Plate 43103£ Case 2054£ Panel NumCNumPriceDue date Product 37102£ Plate O SELECT: take all tuples for which the product is Plate, to give … NumCNumPriceDue date Product ANS1 ANS1<- SELECT from O where Product=Plate

9th December 2016Brookshear, Section 9.26 List of Order Numbers and Products 37102£ Plate 43103£ Case 2054£ Panel NumCNumPriceDue date Product 37Plate 43Case 20Panel O PROJECT: remove attributes CNum, Price and Due date to leave… NumProduct ANS2 ANS2 <- PROJECT Num, Product from O

9th December 2014Brookshear, Section 9.27 Example of a JOIN a1 b2 m5 n2 A.V A.W Relation ARelation B B.X B.Y a1m5 a1n2 b2m5 B2n2 A.V A.W B.X B.Y C <- JOIN A and B

9th December 2014Brookshear, Section 9.28 Definition of JOIN Let A, B, C be relations such that C=JOIN(A,B). Let a be any tuple from A and let b be any tuple from B. The tuples in C are obtained by merging pairs of tuples (a, b). All possible pairs (a, b) are used to construct the tuples in C.

9th December 2014Brookshear, Section 9.29 Relation Containing O.Num and C.Name 37102£ Plate 43103£ Case 2054£ Panel 102Sperry1 The Lane 103Univac15 Retail Road 54Honeywell205 North Street NumCNumPriceDue date Product OC NumNameAddress JOIN: combine tuples in O and C. Then use PROJECT to remove all attributes except O.Num and C.Name.

9th December 2014Brookshear, Section JOIN and then PROJECT 37102£ Plate102Sperry1 The Lane 43103£ Case103Univac15 Retail Road 2054£ Panel54Honey well 205 North Street O.NumO.CNumO.PrcO.DO.PrdC.NumC.NameC.A 37Sperry 43Univac 20Honeywell TEMP <- JOIN O and C where O.CNum=C.Num ANS3 O.NumC.Name ANS3<-PROJECT O.Num, C.Name from TEMP

9th December 2014Brookshear, Section SELECT  The original relation is R1, the new relation created by SELECT is R2 and the conditions on the attribute values in R2 are c1,…cn.  R2 <- SELECT from R1 where c1,…, cn.  Example: ANS1 <- SELECT from O where O.Product=‘Plate’

9th December 2014Brookshear, Section PROJECT  The original relation is R1, the new relation created by PROJECT is R2 and the attributes projected to R2 are att1,…, attn.  R2 <- PROJECT att1,…attn from R1  Example: ANS2 <- PROJECT O.Num, O.Product from O

9th December 2014Brookshear, Section JOIN  The original relations are R1, R2, the new relation created by JOIN is R3 and the conditions on the attribute values in R3 are c1,…cn.  R3 <- JOIN R1 and R2 where c1,…, cn  Example: Temp <- JOIN O, C where O.CNum=C.Num

9th December 2014Brookshear, Section Second Example of JOIN R3 £1500 and O.CNum=C.Num 43103£ Case103Univac15 Retail Road 2054£ Panel54Honey well 205 North Street O.NumO.CNumO.PrcO.DO.PrdC.NumC.NameC.A R3

9th December Join and Keys 3416D1 2822D2 keyforeign key data keydata 16DB1 22DB2 BA C <- JOIN A and B where A.foreign key=B.key 3416D116DB1 2822D222DB2 A.keyA.Foreign key A.dataB.keyB.data C

9th December 2014cf. Brookshear, Section Symmetries A relation does not specify the order of the attributes or the order of the tuples. 102Sperry1 The Lane 103Univac15 Retail Road 54Honeywell205 North Street is the same as 1021 The LaneSperry North Street Honeywell Retail Road Univac CC

9th December 2014cf. Brookshear, Section Repeated Tuples A relation cannot have repeated tuples 102Sperry1 The Lane 103Univac15 Retail Road 54Honeywell205 North Street 54Honeywell205 North Street Not a relation in a relational database.

9th December 2014Birkbeck College18 Attributes in Different Relations An attribute of a given relation is not an attribute of any other relation. E.g. O.CNum is a different attribute from C.Num.

Structured Query Language Standardised language for database queries originally developed and marketed by IBM. An SQL command describes the required information. It does not specify how to obtain that information. 9th December Brookshear, Section 9.2

9th December SQL Statement select O.Num, C.Name from O, C where O.CNum=C.Num Interpretation: JOIN O and C, SELECT those tuples for which O.CNum=C.Num, then PROJECT, retaining the attributes O.Num and C.Name.

9th December 2014Brookshear Ch. 9, problem 1221 Problem 3J 4K In terms of the relations shown below, what is the appearance of the relation RESULT after executing each of these instructions? X relation U V W AZ5 BD3 CO5 Y relation R S a.RESULT <- PROJECT W from X b.RESULT <- SELECT from X where W=5 c.RESULT <- PROJECT S from Y d.RESULT = Y.R.