Relationele Databases 2002/2003



Similar documents
Relationele Databases 2002/2003

Figure 4.12.Insurancedatabase.

Exercises. a. Find the total number of people who owned cars that were involved in accidents

Introduction to SQL ( )

~ We are all goddesses, the only problem is that we forget that when we grow up ~

Introduction to SQL C H A P T E R3. Exercises

Self-test SQL Workshop

GMP-Z Annex 15: Kwalificatie en validatie

The information in this report is confidential. So keep this report in a safe place!

ABN AMRO Bank N.V. The Royal Bank of Scotland N.V. ABN AMRO Holding N.V. RBS Holdings N.V. ABN AMRO Bank N.V.

Maximizer Synergy. BE Houwaartstraat 200/1 BE 3270 Scherpenheuvel. Tel: Fax:

CO-BRANDING RICHTLIJNEN

Exercise 1: Relational Model

employager 1.0 design challenge

Risk-Based Monitoring

IC Rating NPSP Composieten BV. 9 juni 2010 Variopool

Tooway 2015 prices / prijslijst

Load Balancing Lync Jaap Wesselius

Citrix Access Gateway: Implementing Enterprise Edition Feature 9.0

Sample test Secretaries/administrative. Secretarial Staff Administrative Staff

Research Report. Ingelien Poutsma Marnienke van der Maal Sabina Idler

How To Design A 3D Model In A Computer Program

GMP-Z Hoofdstuk 4 Documentatie. Inleiding

IP-NBM. Copyright Capgemini All Rights Reserved

Spread. B&R Beurs. March 2010

Specification by Example (methoden, technieken en tools) Remco Snelders Product owner & Business analyst

Inhoudsopgave. Vak: Web Analysis 1 Vak: Web Information 1 Vak: Web Science 2 Vak: Web Society 3 Vak: Web Technology 4

Storage in Microsoft Azure Wat moet ik daarmee? Bert

General introduction DCE + automotive electronics

THE EMOTIONAL VALUE OF PAID FOR MAGAZINES. Intomart GfK 2013 Emotionele Waarde Betaald vs. Gratis Tijdschrift April

101 Inspirerende Quotes - Eelco de boer - winst.nl/ebooks/ Inleiding

Is het nodig risico s te beheersen op basis van een aanname..

Netezza S's. Robert Hartevelt 31 October IBM Corporation IBM Corporation IBM Corporation

Copyright 2015 VMdamentals.com. All rights reserved.

Software product management. Inge van de Weerd

Cisco Small Business Fast Track Pricing Initiative

5 e CSIT World Sports Games

#BMIT. Welcome. Seminar Business Continuity

Cost overruns in Dutch transportation infrastructure projects

Tooway. consumenten prijzen KASAT. Tooway Nederland Rian BV Bergstraat BL Waalre Prijzen zijn excl 21% BTW

VIDEO CREATIVE IN A DIGITAL WORLD Digital analytics afternoon. Hugo.schurink@millwardbrown.com emmy.brand@millwardbrown.com

Dutch Mortgage Market Pricing On the NMa report. Marco Haan University of Groningen November 18, 2011

Examen Software Engineering /09/2011

IT-waardeketen management op basis van eeuwenoude supply chain kennis

Ons privacybier. Derde privacycafé Data Protection Institute 13 januari 2016 Thomas More Mechelen 21/01/16

OGH: : 11g in de praktijk

Inclusive Education : An international perspective

Hoorcollege marketing 5 de uitgebreide marketingmix. Sunday, December 9, 12

NL VMUG UserCon March

Individual project 2010: Kick- off. 13 April 2010

Corporate Security & Identity

1 Structured Query Language: Again. 2 Joining Tables

Constructief omgaan met conflicten

A Comparative Case Study on the Relationship between EU Unity and its Effectiveness in Multilateral Negotiations

Hot Topics Treasury Seminar

Title page. Title: A conversation-analytic study of time-outs in the Dutch national volleyball. competition. Author: Maarten Breyten van der Meulen

SURFnet Dashboard. Concept, Impressions and ideas. High quality internet for higher Education and Research

ABN AMRO Bank N.V. The Royal Bank of Scotland N.V. ABN AMRO Holding N.V. RBS Holdings N.V. ABN AMRO Bank N.V.

(Optioneel: We will include the review report and the financial statements reviewed by us in an overall report that will be conveyed to you.

Use of trademarks with a reputation as Adwords by competitors: Permissible comparative advertising or impermissible coat-tail riding / dilution?

Proprietary Kroll Ontrack. Data recovery Data management Electronic Evidence

Assuring the Cloud. Hans Bootsma Deloitte Risk Services +31 (0)

Virtualisatie. voor desktop en beginners. Gert Schepens Slides & Notities op gertschepens.be

MIMOA. UID MIMOA Demo 0.8 Version: UID_v0.83.vsd. Versie: UID_v0.83.vsd. UID MIMOA Launch. Matthijs Collard 1. Elements 2. Elements 2 3.

EVALUATION FORM STUDY-VISIT OULU

Market Intelligence & Research Services. CRM Trends Overview. MarketCap International BV Januari 2011

How To Write A Sentence In Germany

Public. Big Data in ASML. Durk van der Ploeg. ASML System Engineering Product Industrialization, October 7, 2014 NTS Eindhoven

POWER OF ATTORNEY FOR EXTRAORDINARY SHAREHOLDERS MEETING OF OCTOBER 5, 2011

Dutch Style Guide for Community

Asking what. a person looks like some persons look like

If farming becomes surviving! Ton Duffhues Specialist Agriculture and society ZLTO Director Atelier Waarden van het Land 4 juni 2014, Wageningen

Information technology specialist (systems integration) Informatietechnologie specialist (systeemintegratie) Professional activities/tasks

ABN AMRO Bank N.V. The Royal Bank of Scotland N.V. ABN AMRO Holding N.V. RBS Holdings N.V. ABN AMRO Bank N.V.

Making Leaders Successful Every Day

How To Get A Ticket To The Brits Engels

Hoofdstuk 2 Samenwerking en afstemming in de zorgketen

De tarieven van Proximus Niet meer gecommercialiseerde Bizz packs

The Art of Cooperation!

ABN AMRO Bank N.V. The Royal Bank of Scotland N.V. ABN AMRO Holding N.V. RBS Holdings N.V. ABN AMRO Bank N.V.

KU Leuven igem Sponsor brochure. Contact : Table of Contents. igem@chem.kuleuven.be. Introduction 2 Previous Sponsors 3

A Central examinations and testing conceptual knowledge in economic contexts

Advance DBMS. Structured Query Language (SQL)

Focused Factories and Efficiency

Auteur. Onderwerp. Datum

How To Use Rabo Internet Banking

Transcription:

1 Relationele Databases 2002/2003 Hoorcollege 5 22 mei 2003 Jaap Kamps & Maarten de Rijke April Juli 2003 Plan voor Vandaag Praktische dingen 3.8, 3.9, 3.10, 4.1, 4.4 en 4.5 SQL Aantekeningen 3 Meer Queries. Theorie Silberschatz et al: hoofdstuk 4: SQL ( 4.5 4.11). 2 3 Docenten: Huishoudelijke Zaken 1. Jaap Kamps, Email: kamps@science.uva.nl 2. Maarten de Rijke, Email: mdr@science.uva.nl URL voor de cursus: http://www.science.uva.nl/~kamps/rdb/, of http://www.science.uva.nl/~mdr/teaching/rdb/0203/ Practicum http://www.science.uva.nl/~borkur/teaching/rdb0203/ Eerste inleveropdracht is nagekeken! Deadline tweede inleveropdracht: 6 juni 2002 3.8 Consider the relational database of Figure 3.39. Give an expression in the relational algebra for each query below. Figure 3.39: employee(person-name,street,city) works(person-name, company-name, salary) company(company-name, city) manages(person-name, manager-name) 4 5 3.8a. Modify the database such that Jones now lives in Newtown. employee Π person-name,street, Newtown ( σ person-name= Jones (employee)) (employee σ person-name= Jones (employee)) 3.8b. Give all employees of First Bank Corporation a 10-percent salary raise. works Π person-name,company-name,1.1 salary( σ company-name= First Bank Corporation (works)) (works σ company-name= First Bank Corporation (works)) 6 7 3.8c Give all managers in this database a 10-percent salary raise. De update syntax staat de referentie naar slechts 1 relatie toe. Omdat deze update zowel toegang moet hebben tot de relatie die we updaten, works, als een andere relatie, manages, moeten we dit stapsgewijs doen. Eerst identificeren we de tuples van works die moeten worden ge-update en bewaren die in een tijdelijke relatie t 1. Dan creëeren we een tijdelijke relatie t 2 met de nieuwe tupples. Als laatste verwijderen we uit works de tuples in t 1, en voegen de tuples in t 2 toe. 3.8c. Give all managers in this database a 10-percent salary raise. t 1 Π works.person-name,company-name,salary( σ works.person-name=manager-name(works manages)) t 2 Π person-name,company-name,1.1 salary(t 1 ) works (works t 1 ) t 2

8 9 3.8d. Give all managers in this database a 10-percent salary raise, unless the salary would be greater than $100,000. In such cases, give only a 3-percent raise. t 1 Π works.person-name,company-name,salary( σ works.person-name=manager-name(works manages)) t 2 Π works.person-name,company-name,salary 1.03( σ t1.salary 1.1>100000(t 1 )) t 2 t 2 (Π works.person-name,company-name,salary 1.1( σ t1.salary 1.1 100000(t 1 ))) works (works t 1 ) t 2 3.8e. Delete all tuples in the works relation for employees of Small Bank Corporation. works works σ company-name= Small Bank Corporation (works) 10 11 3.9 Using the bank example, write relational-algebra queries to find the accounts held by more than two customers in the following ways: a. using an aggregate function t 1 account-numberg count customer-name as num-holders(depositor) Π account-number(σ num-holders>2(t 1 )) b. without using any aggregate functions t 1 (ρ d1 (depositor) ρ d2 (depositor) ρ d3 (depositor)) t 2 σ (d1.account-number=d2.account-number=d3.account-number)(t 1 ) Π d1.account-number( σ (d1.customer-name d2.customer-name d1.customer-name d3.customer-name d2.customer-name d3.customer-name)(t 2 )) 3.10 Consider the relational database of Figure 3.39. Give a relationalalgebra expression for each of the following queries: 3.10a. Find the company with the most employees. t 1 company-nameg count-distinct person-name as num-employees(works) t 2 G max num-employees as max-num-employees(t 1 ) Π company-name(t 1 (num-employees=max-num-employees) t 2 ) 3.10b. Find the company with the smallest payroll. t 1 company-nameg sum salary as payroll (works) t 2 G min payroll as min-payroll(t 1 ) Π company-name(t 1 (payroll=min-payroll) t 2 ) 12 3.10c. Find those companies whose employees earn a higher salary, on average, than the average salary at First Bank Corporation. t 1 company-nameg avg salary as avg-salary(works) t 2 σ company-name= First Bank Corporation (t 1 ) Π t1.company-name(t 1 (t1.avg-salary>t 2.avg-salary) t 2 ) 13 4.4 Let the following relation schemas be given: R = (A, B, C) S = (D, E, F ) Let relations r(r) and s(s) be given. Give an expression in SQL that is equivalent to each of the following queries: a Π A (r) select distinct A from r 14 4.4 (vervolg). Give an SQL expression for each of the following queries: b σ B=17 (r) c r s d Π A,F (σ C=D (r s)) select from r where B = 17 select distinct from r, s select distinct A, F from r, s where C = D 15

16 17 4.5 Let R = (A, B, C) and let r 1 and r 2 both be relations on schema R. Give an expression in SQL that is equivalent to each of the following queries: a r 1 r 2 (select from r 1 ) union (select from r 2 ) b r 1 r 2 Dit kan met de intersect operatie (zoals in a), maar het kan ook met een geneste subquery. 4.5 (vervolg). Give an SQL expression for each of the following queries: b r 1 r 2 c r 1 r 2 select from r 1 where (A, B, C) in (select from r 2 ) select from r 1 where (A, B, C) not in (select from r 2 ) 18 19 4.5 (vervolg). Give an SQL expression for each of the following queries: d Π AB (r 1 ) Π BC (r 2 ) select r 1.A, r 2.B, r 2.C from r 1, r 2 where r 1.B = r 2.B 4.1 Consider the insurance database of Figure 4.12, where the primary keys are underlined. Construct the following SQL queries for this relational database. Figure 4.12: person(driver-id,name,address) car(license,year,model) accident(report-number,location,date) owns(driver-id,license) 20 21 4.1a. Find the total number of people who owned cars that were involved in accidents in 1989. select count (distinct name) from accident, participated, person where accident.report-number = participated.report-number and participated.driver-id = person.driver-id and date between date 1989-00-00 and date 1989-12-31 Dit is niet hetzelfde als het aantal ongelukken in 1989, er kunnen mensen zijn die bij meerdere ongelukken betrokken waren. 4.1b. Find the number of accidents in which the cars belonging to John Smith were involved. select count (distinct *) from accident where exists (select * from participated, person where participated.driver-id = person.driver-id and person.name = John Smith and accident.report-number = participated.report-number) 4.1c. Add a new accident to the database; assume any values for required attributes. We nemen aan dat de driver-id Jones is, en dat Jones een (en precies een) auto model Toyota heeft. Eerst moeten we de licence vinden van de auto. Dan moeten de participated en accident relaties worden aangepast, om het ongeluk te registreren en het aan de genoemde auto te relateren. We nemen de volgende attribuut waarden aan: de location is Berkeley, de date is 2003-05-22, het report-number is 4007 en de damage-amount is 3000. 22 4.1c. Add a new accident to the database; assume any values for required attributes. insert into accident values (4007, 2003-05-22, Berkeley ) insert into participated select owns.driver-id, car.license, 4007, 3000 from person, owns, car where person.name = Jones and person.driver-id = owns.driver-id and owns.license = car.license and car.model = Toyota 23

24 25 4.1d. Delete the Mazda belonging to John Smith. Omdat model geen key van car is, moeten we aannemen dat maar 1 van John Smith s auto s een Mazda is, of dat al zijn auto s Mazda s zijn (de query is hetzelfde). delete car where model = Mazda and license in (select license from person, owns where person.name = John Smith and person.driver-id = owns.driver-id) 4.1e. Update the damage amount for the car with license number AABB2000 in the accident with report number AR2197 to $3000. update participated set damage-amount = 3000 where report-number = AR2197 and driver-id in (select driver-id from owns where license = AABB2000 ) 26 27 Database System Concepts Hoofdstuk 4 Over Structured Query Language of SQL Vorige keer 4.1 tot en met 4.4 Vandaag 4.5 tot en met 4.11. select A 1, A 2,..., A n from r 1, r 2,..., r n where P 28 29 30 31

32 33 34 35 36 37 38 39

40 41 42 43 44 45 46 47

48 49 50 51 52 53 54 55

56 57 58 59 60 61 62 63

64 65 66 67 Overzicht Vandaag Database System Concepts. Hoofdstuk 4: SQL ( 4.5 4.11). Opgaven: 3.8, 3.9, 3.10, 4.1, 4.4 en 4.5. SQL Aantekeningen 3. Meer Queries. 68 69 Volgende Keer bij Relationele Databases End! Opgaven voor volgende keer (5 juni): 4.3 4.8 4.10 Database System Concepts. Integrity & Security (Hoofdstuk 6).