Relational Algebra, R. Ramakrishnan and J. Gehrke1 2003 Ungraded Homework P1 Reminder : Reserves(sid,bid,day) a. Create a table Together(sid1,sid2,day)

Slides:



Advertisements
Similar presentations
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Advertisements

Review Session ER and Relational –ER  Relational –Constraints, Weak Entities, Aggregation, ISA Relational Algebra  Relational Calculus –Selections/Projections/Joins/Division.
Introduction to Database Systems 1 SQL: The Query Language Relation Model : Topic 4.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
1 Lecture 11: Basic SQL, Integrity constraints
SQL: Queries, Constraints, Triggers
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
Database Management Systems 1 Raghu Ramakrishnan SQL: Queries, Programming, Triggers Chpt 5.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5.
CS 405G: Introduction to Database Systems
SQL (2).
CMPT 258 Database Systems SQL: Queries, Constraints, Triggers (Chapter 5) Part II home.manhattan.edu/~tina.tian.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
SQL 2 – The Sequel R&G, Chapter 5 Lecture 10. Administrivia Homework 2 assignment now available –Due a week from Sunday Midterm exam will be evening of.
1 SQL (Simple Query Language). 2 Query Components A query can contain the following clauses –select –from –where –group by –having –order by Only select.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Rutgers University SQL: Queries, Constraints, Triggers 198:541 Rutgers University.
1 Rewriting Minus Queries Using Not In SELECT S.sname FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ MINUS.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
SLIDE 1IS Fall 2002 Database Management: Discussion Session University of California, Berkeley School of Information Management and.
1 Chapter 5 SQL: QUERIES, CONSTRAINTS, TRIGGERS. 2 INTRODUCTION - The current presentation is consistent with both SQL-92 and SQL: 99 (differences will.
1 The Oracle Database System Querying the Data Database Course The Hebrew University of Jerusalem.
1 Rewriting Intersect Queries Using In SELECT S.sid FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ INTERSECT.
1 Advanced SQL. 2 Consider the following relations: –pupil (pupil_name, address, class, birthyear) –subject (subject_name, class, teacher) –grades (pupil_name,
Exercises Find the names of sailors who’ve reserved boat #103 { N |  S  Sailors (S.name = N.name   R  Reserves(S.sid = R.sid  R.bid = 103)) }
CSC343 – Introduction to Databases - A. Vaisman1 SQL: Queries, Programming, Triggers.
Introduction to SQL Basics; Christoph F. Eick & R. Ramakrishnan and J. Gehrke 1 Introduction to SQL Basics --- SQL in 45 Minutes Chapter 5.
Christoph F. Eick: Designing E/R Diagrams 1 Designing E/R Diagrams Updated: January
NFL E/R Design Problem Design an Entity-Relationship Diagram that models the following objects and relationships in the world of football (NFL): teams,
Midterm Review Zaki Malik October 09, Basic Operators Covered.
CMPT 258 Database Systems Instructor: Tina Tian. General Information Office: RLC 203A Office Hour: Wednesday 1:30 - 4:30.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L6_SQL(1) 1 SQL: Queries, Constraints, Triggers Chapter 5 – Part 1.
SQL Part I: Standard Queries. COMP-421: Database Systems - SQL Queries I 2 Example Instances sid sname rating age 22 debby debby lilly.
Database Management Systems,1 Relational Calculus.
Unit 5/COMP3300/ SQL: Queries, Programming, Triggers Chapter 5.
SQL: Queries, Programming, Triggers. Example Instances We will use these instances of the Sailors and Reserves relations in our examples. If the key for.
1 Database Systems ( 資料庫系統 ) October 24, 2005 Lecture #5.
Mapping E/R Diagrams to Relational Database Schemas
Introduction to SQL ; Christoph F. Eick & R. Ramakrishnan and J. Gehrke 1 Using SQL as a Query Language COSC 6340.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Constraints, Triggers Chapter 5.
CMPT 258 Database Systems SQL Queries (Chapter 5).
Data Modeling Using the Entity-Relationship (ER) Data Model.
CMPT 258 Database Systems Final Exam Review.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
1 SQL: The Query Language (Part II). 2 Expressions and Strings v Illustrates use of arithmetic expressions and string pattern matching: Find triples (of.
1 SQL: Structured Query Language (‘Sequel’) Chapter 5.
CSCI 4333 Database Design and Implementation – Exercise (2) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
SQL: The Query Language Part 1 R &G - Chapter 5 The important thing is not to stop questioning. Albert Einstein.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
Mapping E/R to RM, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 Mapping E/R Diagrams to Relational Database Schemas Second Half of Chapter.
Dr. Eick’s: Homework Solutions COSC Ungraded Homework P1 Reminder : Reserves(sid,bid,day) a. Create a table Together(sid1,sid2,day) that contains.
SQL CS 186, Spring 2007, Lecture 7 R&G, Chapter 5 Mary Roth   The important thing is not to stop questioning. Albert Einstein Life is just a bowl of.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Basic SQL Queries.
1 CS122A: Introduction to Data Management Lecture 9 SQL II: Nested Queries, Aggregation, Grouping Instructor: Chen Li.
1 CS122A: Introduction to Data Management Lecture 8 Introduction to SQL Instructor: Chen Li.
DataBase - Check 01 DataBase 2 nd year Computer Science & Engineer 1.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
© פרופ' יהושע שגיב, האוניברסיטה העברית
01/31/11 SQL Examples Edited by John Shieh CS3754 Classnote #10.
SQL The Query Language R & G - Chapter 5
Database Systems October 14, 2009 Lecture #5.
Basic SQL Lecture 6 Fall
CSCI 6315 Applied Database Systems – Exercise (1)
Database Applications (15-415) SQL-Part II Lecture 9, February 04, 2018 Mohammad Hammoud.
Database Systems 10/13/2010 Lecture #4.
Solution Problem1 Exam0 ssn Sal empl. name name Person Team city contr
CS 405G: Introduction to Database Systems
SQL: The Query Language Part 1
CS4222 Principles of Database System
SQL: Structured Query Language
Presentation transcript:

Relational Algebra, R. Ramakrishnan and J. Gehrke Ungraded Homework P1 Reminder : Reserves(sid,bid,day) a. Create a table Together(sid1,sid2,day) that contains all pairs of sailors that have a reservation for the same boat on the same day.  (Reserves1 (1  sid1),Reserves)  (Reserves2 (1  sid2),Reserves)  (Together,  sid1,sid2,day (Reserves1 |X| Reserves2)) b. Give the sids of all sailors that have a reservation for 10/13/2003 but not for 10/17/2003.  sid (  day=10/13/2003 (Reserves))   sid (  day=10/17/2003 (Reserves))

Relational Algebra, R. Ramakrishnan and J. Gehrke Ungraded Homework P1 (cont) c. Give the name and sid of all sailors that have reservations for all red boats  (Tempsids,  sid,bid (Reserves) /  bid (  color=red (Boats)) )  sid,sname (Tempsids |X| Sailors) d. Give the name and sid of all sailors that have exactly one reservation for 11/11/2003  (Reserves2 (1  sid2,2  bid2),  day=11/11/2003 Reserves)  (2+R, (  sid (  day=11/11/2003 (Reserves) |X| sid=sid2 and bid  bid2 Reserves2))  sid,sname ((  sid (Reserves)  2+R) |X| Sailors))

Relational Algebra, R. Ramakrishnan and J. Gehrke3 P2 All but one boat problem SELECT R.sid FROM Reserves R GROUPED BY R.sid HAVING COUNT(DISTINCT R.bid)) + 1= (SELECT count(*) FROM Boats Bo) Remarks: still needs to be tested if the query runs on ORACLE9i; counting, instead of checking the real bid’s is okay because of referential integrity.

Relational Algebra, R. Ramakrishnan and J. Gehrke4 P3 NFL E/R Design Problem Design an Entity-Relationship Diagram that models the following objects and relationships in the world of football (NFL): teams, players, games, managers and contracts. Each (NFL-) team has a unique team name, and a city it plays in. Each person being part of the NFL-world has a unique ssn and a name. Additionally, for players their weight, height, position and birth dates are of importance. Players have a contract with at most one team and receive a salary for their services, and teams have at least 24 and at most 99 players under contract. Each team has one to three managers; managers can work for at most 4 teams and receive a salary for each of their employments. Players cannot be managers. A game involves a home-team and visiting-team; additionally, the day of the game, and the score of the game are of importance; teams play each other several times in a season (not on the same day!). Moreover, for each game played we like to know which players participated in the game and how many minutes they played. Indicate the cardinalities for each relationship type; assign roles (role names) to each relationship if there are ambiguities! Use sub-types, if helpful to express constraints!

Team empl. contr name city Manager Player Person name ssn weightpos birthd height Game play played-in. Day min score HomeVisit Sal (1,3) (0,4) (1,1) (24,99) (0,1) (22,*) (0,*) NFL E/R Problem (0,*) isa Scoring: 1.Play relationship a Set: 3 2.Person/Player/Manager: 3 3.Weak Game Entity: 3 4.Played-in: 2 5.Can Only Play once on a day: 1 6.Contract: 3 7.Salary, score, min attribute: 3

Relational Algebra, R. Ramakrishnan and J. Gehrke6 Using the Default Mapping to Map the E/R Diagram to the Relational Data Model Game(home, visit, day, score) Played_in(home,visit, day, ssn, min) Player(ssn, birthd, pos,…) Team(name, city) Person(ssn, name) Contract(Team,Player,Salary)

Relational Algebra, R. Ramakrishnan and J. Gehrke7 SQL-Queries B1 ) “Give the dates of all reservations for red boats” [2] SELECT R.day FROM Reserve R, Boat B WHERE R.bid = B. bid AND B.color = ‘red’ B2) “ Give the boats (return bid ) that have at least 2 reservations for 5/5/2003 ” [4] SELECT DISTINCT R1.bid FROM Reserve R1, Reserve R2 WHERE R1.day= ‘5/5/03’ AND R2.day = ‘5/5/03’ AND R1.bid=R2.bid AND R1.Sid <> R2.Sid

Relational Algebra, R. Ramakrishnan and J. Gehrke8 SQL-Queries B2) “ Give the name and sid of all sailors that do not have any reservations for green boat(“There is no green boat that is reserved by this sailor”) [4] Wrong: SELECT S.sname, S.sid FROM Sailor S, Reserve R, Boat B WHERE S.sid = R.sid AND R.bid=B.bid AND not(B.color = ‘green’)

Relational Algebra, R. Ramakrishnan and J. Gehrke9 SQL-Queries B2) “ Give the name and sid of all sailors that do not have any reservations for green boat(“There is no green boat that is reserved by this sailor”) [4] Correct: SELECT S.sname, S.sid FROM Sailor S EXECPT SELECT S.sname S.sid FROM Sailor S, Reserve R, Boat B WHERE S.sid = R.sid AND R.bid=B.bid AND B.color = ‘green’