Midterm Review Zaki Malik October 09, 2008. Basic Operators Covered.

Slides:



Advertisements
Similar presentations
SQL: The Query Language Part 1 R &G - Chapter 5 Life is just a bowl of queries. -Anon (not Forrest Gump)
Advertisements

Constraints in Entity-Relationship Models Zaki Malik September 18, 2008.
1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
1 TRC vs DRC 한욱신. 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC.
Relational Algebra Rohit Khokher. Relational Algebra Set Oriented Operations UnionIntersectionDifference Cartesian Product Relation Oriented Operations.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
Review Session ER and Relational –ER  Relational –Constraints, Weak Entities, Aggregation, ISA Relational Algebra  Relational Calculus –Selections/Projections/Joins/Division.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
1 Lecture 11: Basic SQL, Integrity constraints
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
SQL and Relational Algebra Zaki Malik September 02, 2008.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
SQL Review.
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
Weak Entity Sets. Occasionally, entities of an entity set need “help” to identify them uniquely. Example. Crews might have a number and some description,
Weak Entity Sets. Occasionally, entities of an entity set need “help” to identify them uniquely. Entity set E is weak if in order to identify entities.
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.
D ATABASE S YSTEMS I A DMIN S TUFF. 2 Mid-term exam Tuesday, Oct 2:30pm Room 3005 (usual room) Closed book No cheating, blah blah No class on Oct.
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.
FALL 2004CENG 351 File Structures and Data Managemnet1 Relational Algebra.
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.
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.
1 Relational Algebra. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
The Entity-Relationship Data Model
Dec 15, 2003Murali Mani Transactions and Security B term 2004: lecture 17.
1 The Oracle Database System Querying the Data Database Course The Hebrew University of Jerusalem.
Cs3431 Transactions, Logging and Security. cs3431 Transactions: What and Why? A set of operations on a database must appear as one “unit”. Example: Consider.
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.
Relational Algebra.
Introduction to SQL Basics; Christoph F. Eick & R. Ramakrishnan and J. Gehrke 1 Introduction to SQL Basics --- SQL in 45 Minutes Chapter 5.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L6_SQL(1) 1 SQL: Queries, Constraints, Triggers Chapter 5 – Part 1.
Databases : Entity-Relationship Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman.
ER Data Models Ctd. CSET 3300.
SQL Part I: Standard Queries. COMP-421: Database Systems - SQL Queries I 2 Example Instances sid sname rating age 22 debby debby lilly.
ICS 321 Fall 2009 SQL: Queries, Constraints, Triggers Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 9/8/20091Lipyeow.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Relational Algebra.
ICS 321 Fall 2011 The Relational Model of Data (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 8/29/20111Lipyeow.
1 Database Systems ( 資料庫系統 ) October 24, 2005 Lecture #5.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity-Relationship Model
Home Work. Design Principles and Weak Entity Sets.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
CMPT 258 Database Systems Relational Algebra (Chapter 4)
CMPT 258 Database Systems SQL Queries (Chapter 5).
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.
Final Review Zaki Malik November 20, Basic Operators Covered.
1 CS122A: Introduction to Data Management Lecture #7 Relational Algebra I Instructor: Chen Li.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Basic SQL Queries.
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.
1 CS122A: Introduction to Data Management Lecture 8 Introduction to SQL Instructor: Chen Li.
Database Systems (資料庫系統)
Query-by-Example (QBE)
Constraints in Entity-Relationship Models
CPSC-310 Database Systems
Relational Algebra Chapter 4, Part A
Database Systems 10/13/2010 Lecture #4.
CS4222 Principles of Database System
Presentation transcript:

Midterm Review Zaki Malik October 09, 2008

Basic Operators Covered

Renaming If two relations have the same attribute, disambiguate the attributes by prefixing the attribute with the name of the relation it belongs to. How do we answer the query “Name pairs of students who live at the same address”? Students(Name, Address) – We need to take the cross-product of Students with itself? – How do we refer to the two “copies” of Students? – Use the rename operator. RA: : give R the name S; R has n attributes, which are called A 1,A 2,...,A n in S SQL: Use the AS keyword in the FROM clause: Students AS Students1 renames Students to Students1. SQL: Use the AS keyword in the SELECT clause to rename attributes. S ( A 1,A 2,... A n ) (R)

Q5: Find the names of sailors who have reserved a red or a green boat Reserves(sid, bid, day) Sailors(sid, sname, rating, age) Boats(bid, bname, color) Solution: π sname (σ color= ‘ red ’ or color = ‘ green ’ Boats ∞ Reserves ∞ Sailors) Reserves(sid, bid, day) Sailors(sid, sname, rating, age) Boats(bid, bname, color)

Q6: Find the names of sailors who have reserved a red and a green boat Reserves(sid, bid, day) Sailors(sid, sname, rating, age) Boats(bid, bname, color) Solution: π sname (σ color= ‘ red ’ and color = ‘ green ’ Boats ∞ Reserves ∞ Sailors) Reserves(sid, bid, day) Sailors(sid, sname, rating, age) Boats(bid, bname, color) A ship cannot have TWO colors at the same time π sname (σ color= ‘ red ’ Boats ∞ Reserves ∞ Sailors) ∩ π sname (σ color = ‘ green ’ Boats ∞ Reserves ∞ Sailors)

Basic SQL Query SELECT [DISTINCT] target-list FROM relation-list WHERE qualification; Relation-list: A list of relation names (possibly with range- variable after each name). Target-list: A list of attributes of relations in relation-list Qualification: conditions on attributes DISTINCT: optional keyword for duplicate removal. – Default = no duplicate removal!

ACID Properties ACID Properties are: – Atomic : Whole transaction or none is done. – Consistent : Database constraints preserved. – Isolated : It appears to the user as if only one process executes at a time. – Durable : Effects of a process survive a crash. Optional: weaker forms of transactions are often supported as well.

8 Representing “Multiplicity” Show a many-one relationship by an arrow entering the “one” side. Show a one-one relationship by arrows entering both entity sets. In some situations, we can also assert “exactly one,” i.e., each entity of one set must be related to exactly one entity of the other set. To do so, we use a rounded arrow. Many One One ) Exactly One

9 Weak Entity Sets Occasionally, entities of an entity set need “help” to identify them uniquely. Entity set E is said to be weak if in order to identify entities of E uniquely, we need to follow one or more many-one relationships from E and include the key of the related entities from the connected entity sets.

10 Example name is almost a key for football players, but there might be two with the same name. number is certainly not a key, since players on two teams could have the same number. But number, together with the Team related to the player by Plays- on should be unique. PlayersTeams Plays- on name number Double diamond for supporting many-one relationship. Double rectangle for the weak entity set.

11 Weak Entity-Set Rules A weak entity set has one or more many-one relationships to other (supporting) entity sets. – Not every many-one relationship from a weak entity set need be supporting. The key for a weak entity set is its own underlined attributes and the keys for the supporting entity sets. – E.g., player-number and team-name is a key for Players in the previous example.

Midterm Points Distribution Relational Algebra - 36 points – 8 small questions SQL / Databases – 32 points – 6 small questions ER Modeling – 32 points – 3 questions

Sample Exam Solutions

14

15 Real RDBMSs treat relations as bags of tuples. SQL, the most important query language for relational databases, is actually a bag language.

16

17

18 a set of four “Iron Chefs”, each one an expert in precisely one of the following cuisines: Chinese, French, Italian, and Japanese. Iron Chefs are famous; their name serves to identify them uniquely.

19 Each episode, identified by an episode number,… features a competition between a challenger and one of the Iron Chefs. Each challenger is also quite famous; his/her name and restaurant are enough to identify the challenger. The challenger selects the Iron Chef he/she wants to compete with.

Each competition features a secret ingredient unveiled at the beginning of the episode. The secret ingredient never repeats, i.e., two different competitions do not have the same secret ingredient. The challenger and the selected Iron Chef each have one hour to prepare a set of dishes that articulate the theme ingredient. 20

At the end of the hour, a panel of four judges tastes these dishes. A person can be a judge in multiple competitions. Each judge awards each competitor a score; the maximum score is 20. The competitor with the maximum number of points wins. There are no ties!

NOTES Cuisine is an enumerated attribute with four possible values: Chinese, French, Italian, and Japanese. There are no ties. The winner is the competitor with the most points. The time allotted for each competition is one hour.

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38