Relational Algebra for sets Introduction to relational algebra for bags

Size: px
Start display at page:

Download "Relational Algebra for sets Introduction to relational algebra for bags"

Transcription

1 Relational Algebra for sets Introduction to relational algebra for bags Thursday, September 27,

2 Terminology for Relational Databases Slide repeated from Lecture 1... Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking 2 relation Each entry in the table is called a row or a tuple. Sometimes an entry in the table is called a record. The instance is the current set of rows (or tuples).

3 Codd s Original Relational Algebra Operators Eight operators defined for sets: project select cross product join union intersection difference division Plus renaming (to provide names for the relation & attributes of answer) 3

4 Project operator (π) in relational algebra Operator invented by Codd (not part of set theory) Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Consider the query: π Number, Owner Account list of attributes (to retain) 4

5 Project operator (π) in relational algebra Always applied to single relation a unary operator For the query: π Number, Owner Account query answer is: Number Owner 101 J. Smith 102 W. Wei 103 J. Smith 104 M. Jones 105 H. Martin 5

6 Project operator (π): another example Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Consider the query: π Owner Account list of attributes (to retain) 6

7 Project operator example (cont.) Consider the query: π Owner Account Query answer is: Owner W. Wei J. Smith M. Jones H. Martin In relational algebra defined on sets, the query answer is a set. J. Smith appears just once in the query answer. 7

8 Select operator ( ) in relational algebra invented by Codd (not part of set theory) Given the following relation (and instance) Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Consider the query: Balance < 3000 Account 8

9 Select operator example (cont.) Balance < 3000 Account The select predicate is evaluated for each tuple Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking 9

10 Select operator example (cont.) For this query: Balance < 3000 Account The query answer is: Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 104 M. Jones checking 10

11 Select operator in relational algebra Always applied to a single relation a unary operator Balance < 3000 Account the select operator a relation name (or a relation expression) 11 the predicate: an attribute a comparator (, >,, =,, <) an attribute or a constant

12 Examples using the select operator Balance < 3000 Account Number = 103 Account Balance = Number Account Attribute compared to attribute! Type = checking ( Balance < 3000 Account) relational expression! Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking 12

13 Example (Useless) Query with Answer Account Query answer is empty. But that s allowed. Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Type= checking AND Type = savings ATMWithdrawal Number Owner Balance Type But why is this a useless query? 13

14 Select and Project can be combined Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith instance. savings 104 M. Jones checking 105 H. Martin 10, checking Owner ( Balance < 3000 Account) Balance < 3000 ( Owner, Balance Account) Note: two queries are equivalent if they are guaranteed to return the same query answer for every possible DB Owner ( Balance < 3000 ( Owner, Balance Account)) Balance < 3000 ( Owner Account) Is this one well-formed? Which pairs of these queries are equivalent, if any? 14

15 Cross Product an operator from set theory Suppose.. A = {a, b, c} B = {1, 2} then in set theory, the cross product is defined as: A X B = {(a, 1), (b, 1), (c, 1), (a, 2), (b, 2), (c, 2)} A X B is a set consisting of pairs (2-tuples) where each pair consists of an element from A and an element from B 15

16 Cross Product in Set Theory Suppose.. A = {a, b, c} B = {1, 2} C = {x, y} then A X B = {(a, 1), (b, 1), (c, 1), (a, 2), (b, 2), (c, 2)} and (A X B) X C = {((a,1),x), ((b,1),x), ((c,1),x), ((a,2),x), ((b,2),x), ((c,2),x), ((a,1),y), ((b,1),y), ((c,1),y), ((a,2),y), ((b,2),y), ((c,2),y)} 16

17 Cross Product in Relational Algebra vs. Set Theory Given A = {a, b, c} B = {1, 2} C = {x, y} then (A X B) X C, in set theory, = {((a,1),x), ((b,1),x), ((c,1),x), ((a,2),x), ((b,2),x), ((c,2),x), ((a,1),y), ((b,1),y), ((c,1),y), ((a,2),y), ((b,2),y), ((c,2),y)} Codd simplified it in relational algebra to: {(a,1,x), (b,1,x), (c,1,x), (a,2,x), (b,2,x), (c,2,x), (a,1,y), (b,1,y), (c,1,y), (a,2,y), (b,2,y), (c,2,y)} by eliminating parentheses. flattening the tuples. 17

18 Same slide with color eliminated Given A = {a, b, c} B = {1, 2} C = {x, y} with the cross product (A X B) X C in set theory = {((a,1),x), ((b,1),x), ((c,1),x), ((a,2),x), ((b,2),x), ((c,2),x), ((a,1),y), ((b,1),y), ((c,1),y), ((a,2),y), ((b,2),y), ((c,2),y)} Codd simplified it in relational algebra to: {(a,1,x), (b,1,x), (c,1,x), (a,2,x), (b,2,x), (c,2,x), (a,1,y), (b,1,y), (c,1,y), (a,2,y), (b,2,y), (c,2,y)} by eliminating parentheses. flattening the tuples. 18

19 Example Database to show how cross product can be used in a query Imagine that we have these two relations in a university database. Teacher (t-num, t-name) Course (c-num, c-name) In reality, the relations would probably be more detailed with attribute names as follows: Teacher (Number, Name, Office, ) Course (Number, Name, Description) Taught-By (Quarter, Course, Section, Teacher, TimeDays) etc. 19

20 X cross product operator produces every possible combination Teacher t-num t-name Cross product produces: every possible combination of a teacher and a course Course c-num c-name 101 Smith 586 Intro to DB 105 Jones 533 Intro to OS 110 Fong Teacher X Course t-num t-name c-num c-name 101 Smith 586 Intro to DB 105 Jones 586 Intro to DB 110 Fong 586 Intro to DB 101 Smith 533 Intro to OS 105 Jones 533 Intro to OS 110 Fong 533 Intro to OS 20

21 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Cross product followed by select. 21

22 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) notice the columns 22 Number Owner Balance Type Account T-id Date Amount

23 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 23

24 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 24

25 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 25

26 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Yes! Place in query answer. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/

27 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Yes! Place in query answer. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

28 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

29 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

30 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking All combinations fail! Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

31 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

32 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

33 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Why? Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

34 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking No! Throw it away. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

35 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking The first three fail. Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/

36 Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Yes! Place in query answer. Final answer: Deposit Account T-id Date Amount /22/ /29/ /29/ /02/00 10, Balance > 1000 AND Number =Account (Account X Deposit) Number Owner Balance Type Account T-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/ H. Martin 10, checking /02/00 10,

37 join operator (defined using σ and X) Account Deposit Check Number Owner Balance Type Account Transaction-id Date Amount Account Check-number Date Amount A.Number=Deposit.Account (Account X Deposit) Notice: select condition in first query is used as join condition in second query. is equivalent to Account A.Number=Deposit.Account Deposit 37

38 A few details about join Each simple Boolean predicate in the join condition must compare an attribute from one relation to an attribute in the other relation. In this query: Account A A.Number=D.Account AND D.type= checking Deposit D the D.type = checking isn t a JOIN condition. If you have a join with NO condition, then it is a cross product by definition. 38

39 Join.. with all six comparators Student advisor=number Faculty Student S S.age < F.age Faculty F Student S S.salary F.salary Faculty F etc. Join is sometimes called theta-join or θ-join where the θ represents any of the 6 comparators (<, >, =,,, ) (In PostgreSQL the 6 comparators are (<, >, =,!= or <>, >=, <=).) The most common join (with equality) is called equi-join 39

40 Exercise Class(course, term, room, teacher) teacher is foreign key referencing Faculty.id Faculty(id, name, office) Student(id, name, major) Enrolled(id, course, term, grade) id is a foreign key referencing Student.id (course, term) together is a foreign key referencing Class.(course, term) 40

41 Faculty(id, name, office) Class(course, term, room, teacher) Enrolled(id, course, term, grade) Student(id, name, major) Provide sample data with several faculty, students, and classes in several terms. Write a relational algebra query that lists faculty id and student id pairs where the student is enrolled in a class that is taught by the faculty member. Write a relational algebra query that lists faculty ids for faculty who teach at least two classes in the same term. 41

42 Equi-join (reminder) equi join: Account Number=Account Deposit When the join is based on equality, then we always have two identical attributes (columns) in the answer. Number Owner Balance Type Account Trans-id Date Amount 102 W. Wei checking /22/ W. Wei checking /29/ M. Jones checking /29/ H. Martin 10, checking /2/ If we use natural join, the duplicate column is eliminated. 42

43 Natural join Joins two relations by checking for equality on all pairs of attributes with the same name. Eliminates duplicate columns from query answer. This is risky; your queries might change if you change your schema. (If you use natural join in SQL queries.) This is great for textbooks queries are simpler. 43

44 NATURAL JOIN NATURAL JOIN like a macro that joins tables with an equality check for all attributes with the same name. Course (CNumber, CName, Description) Teacher (TNumber, TName, Phone) Offering (CNumber, TNumber, Time, Days, Room) 44 Teacher Offering Course This query (with natural join) does just what you want. But it requires the schema to be just right.

45 A simple relational algebra query with zero operators Relational algebra query: Student A relation name, by itself, is a valid relational algebra query. It returns all of the tuples in the relation in the query answer. 45

46 Relational Algebra Operators There are eight operators project select union intersection difference cross product join division Three operators from set theory renaming (to provide names for the relation & attributes of answer) 46

47 Union in set theory vs. relational algebra In set theory, the elements of a set can be all different types S = { a, 7053, (1, 2, Smith ), (3, 4, 5, 6, 7, 8, 9)} (atomic values as well as tuples of different lengths) In set theory, you can take the union (or intersection or difference) of any two sets. A = {1, (3, 4, a ), 5.3} B = {7, 1, (2, 3)} A B = {1, (3, 4, a ), 5.3, 7, (2, 3)} A B = {1} A B = {(3, 4, a ), 5.3} But in relational algebra, relations must have the same shape (be union-compatible) before you can take,,. 47

48 Union Compatible Two relations are union-compatible if they have the same number of attributes and the corresponding attributes have the same name and are defined on the same domains. (this is imprecise because domains/datatypes may not be precise; domains should be compatible) Suppose we have these relations: Checking-Account (num, owner, balance) Savings-Account (num, owner, balance) These are union-compatible relations. 48

49 Union in Relational Algebra Consider this query: Checking-account Savings-account Checking-account Savings-account num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, J. Smith

50 Intersection in Relational Algebra (example 1) Consider this query: Checking-account Savings-account Checking-account Savings-account num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith What s the answer to this query? 50 50

51 Intersection in Relational Algebra (ex. 1 cont.) What is the answer to this query: Checking-account Savings-account Checking-account Savings-account What s the answer to this query? num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith It s empty. There are no tuples that are in both relations

52 Intersection in Relational Algebra (example 2) What s the answer to this query? ( owner Checking-account) ( owner Savings-account) Checking-account Savings-account num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith

53 Intersection in Relational Algebra (ex. 2 cont.) Intermediate query answers ( owner Checking-account) ( owner Savings-account) owner J. Smith W. Wei M. Jones H. Martin owner J. Smith Query answer is (using attribute name from Checkingaccount): owner J. Smith 53 53

54 Set Difference: Relational Algebra (ex. 1) Consider this query: Checking-account Savings-account Find all the tuples (rows) that are in the Checking-account relation that are not in the Savings-account relation. Checking-account Savings-account num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith What is the answer? 54 54

55 Set Difference: Relational Algebra (ex. 1 cont.) Consider this query: Checking-account Savings-account Find all the tuples (rows) that are in the Checking-account relation that are not in the Savings-account relation. Checking-account Savings-account num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith What is the answer? All of the rows in the checking-account table

56 Set Difference: Relational Algebra (ex. 2) ( owner Checking-account) ( owner Savings-account) Checking-account Savings-account num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith Compute the intermediate query answers. Then, what is the final query answer? 56 56

57 Set Difference: Relational Algebra (ex. 2 cont.) ( owner Checking-account) ( owner Savings-account) 57 Checking-account Savings-account Compute the intermediate query answers. Then, what is the final query answer? num owner balance 101 J. Smith W. Wei M. Jones H. Martin 10, num owner balance 103 J. Smith owner W. Wei M. Jones H. Martin 57

58 Another example for set operators Graduate-student (id, name, GPA, phone) Undergrad-student (id, name, GPA, phone) These tables are union-compatible; we can issue the following queries: 1. Graduate-student Undergrad-student 2. Graduate-student Undergrad-student 3. Undergrad-student Graduate-student What do these queries compute, described in English? 58 58

59 Relational Algebra: Divide Operator Suppose we have this extra table, in the Bank database: Account-types Type checking savings Suppose we would like to know which customers have at least one account of each type of account. That is, we want to know who has accounts of ALL the types. 59

60 We can use the Divide operator in Rel. Alg. ( Owner, Type Account) Account-types Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Account-types Type checking savings Owner J. Smith Find account owners who have ALL types of accounts. 60

61 Divide Operator For R S where R (r1, r2, r3, r4) and S(s1, s2) Since S has two attributes, there must be two attributes in R (say r3 and r4) that are defined on the same domains, respectively, as s1 and s2. We could say that (r3, r4) is union-compatible with (s1, s2). The query answer has the remaining attributes (r1, r2). And the answer has a tuple, (r1, r2), in the answer if the (r1, r2) value appears with every S tuple in R. 61

62 How does divide work? ( Owner, Type Account) Account-types Owner, Type Account Owner Type J. Smith checking W. Wei checking J. Smith savings M. Jones checking H. Martin checking Can we find an owner where there are enough tuples in this table for that owner so that we can match EVERY tuple in Account-types? List all such owners. Account-types Type checking savings Owner 62

63 Write this query in relational algebra Customer (Number, Name, Address, CRating, CAmount, CBalance, Salesperson) Salesperson (Number, Name, Address, Office) Find the name of salespersons (if there are any) who are assigned to ALL customers. S.Number, S.Name ((( Salesperson, Number Customer) ( Number Customer)) X Salesperson=S.Number Salesperson) 63

64 Why do we use Relational Algebra? Because: It is mathematically defined We can prove that two relational algebra expressions are equivalent. For example: cond1 ( cond2 R) cond2 ( cond1 R) cond1 AND cond2 R ( cond1 R) ( cond2 R) R1 cond R2 cond (R1 R2) 64

65 Equivalences for AND, OR, and NOT cond1 OR cond2 R ( cond1 R) ( cond2 R) cond1 AND cond2 R ( cond1 R) ( cond2 R) cond1 AND NOT cond2 R ( cond1 R) ( cond2 R) The WHERE clause (and the predicate for the operator) may contain AND, OR, as well as NOT. 65

66 Uses of Relational Algebra Equivalences To help query writers they can write queries in several different ways To help query optimizers they can choose among different ways to execute the query and in both cases we know for sure that the two queries (the original and the replacement) are identical that they will produce the same answer on all database instances 66

67 Queries Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Notice that a query is expressed against the schema. Balance > 1000 AND Number =Account (Account X Deposit) But the query runs or executes against the instance (the data) And may give different answers 67 on different instances Owner J. Smith W. Wei M. Jones H. Martin

68 Comments on Queries Account Number Owner Balance Type 101 J. Smith checking 102 W. Wei checking 103 J. Smith savings 104 M. Jones checking 105 H. Martin 10, checking Notice that the answer to a query is always a relation! It doesn t have a name. The attribute names are taken from the input tables. It might or might not have any rows. 68 Owner J. Smith W. Wei M. Jones H. Martin

69 Comments on Queries Because the answer to a relational query is always a table. we can use the answer from one query as input to another query. This means that we can create arbitrarily complex queries! A relational query languages is closed if it has this property. 69

70 Example of Codd s Definition of a Relation Suppose we have a relation defined as: Person(name, salary, num, status) with domains defined as: Name-values = {all possible strings of 30 characters} Sal-values = {real numbers between 0 and 100,000} Status-values = { f, p } Num-values = {integers between 0 and 9999} any instance of the relation is always a subset ( ) of: Name-values X Sal-values X Num-values X Status-values Note: a domain is a set of simple, atomic values. 70

71 Mathematical Definition of a Relational DB (cont.) Each (instance of a) relation is a subset of the cross product of it s domains. One element of a relation is called a tuple. A relation is ALWAYS a set by definition. If you add the element 2 to the set {1, 2, 3, 4} the resulting set is {1, 2, 3, 4} If you add the tuple {101, J. Smith, , checking } to the relation on the next slide, you still only have five tuples. 71

72 Can we define tables (to use in relational algebra)? If you need to define a relation. You could say something like: Let R = {( John, 5, male ), ( Sue, 6, female )} or let R be the table Name Age Gender John 5 male Sue 6 female and then use R in expressions like R X Student or whatever

Relational Query Languages: Relational Algebra. Juliana Freire

Relational Query Languages: Relational Algebra. Juliana Freire Relational Query Languages: Relational Algebra Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports simple, powerful QLs: Simple

More information

CS2300: File Structures and Introduction to Database Systems

CS2300: File Structures and Introduction to Database Systems CS2300: File Structures and Introduction to Database Systems Lecture 9: Relational Model & Relational Algebra Doug McGeehan 1 Brief Review Relational model concepts Informal Terms Formal Terms Table Relation

More information

Relational Model and Relational Algebra

Relational Model and Relational Algebra Relational Model and Relational Algebra CMPSCI 445 Database Systems Fall 2008 Some slide content courtesy of Zack Ives, Ramakrishnan & Gehrke, Dan Suciu, Ullman & Widom Next lectures: Querying relational

More information

Relational Database: The Relational Data Model; Operations on Database Relations

Relational Database: The Relational Data Model; Operations on Database Relations Relational Database: The Relational Data Model; Operations on Database Relations Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin Overview

More information

2.2.2.Relational Database concept

2.2.2.Relational Database concept Foreign key:- is a field (or collection of fields) in one table that uniquely identifies a row of another table. In simpler words, the foreign key is defined in a second table, but it refers to the primary

More information

Announcements. Relational Model & Algebra. Example. Relational data model. Example. Schema versus instance. Lecture notes

Announcements. Relational Model & Algebra. Example. Relational data model. Example. Schema versus instance. Lecture notes Announcements Relational Model & Algebra CPS 216 Advanced Database Systems Lecture notes Notes version (incomplete) available in the morning on the day of lecture Slides version (complete) available after

More information

COMP 244 DATABASE CONCEPTS AND APPLICATIONS

COMP 244 DATABASE CONCEPTS AND APPLICATIONS COMP 244 DATABASE CONCEPTS AND APPLICATIONS Relational Algebra And Calculus 1 Relational Algebra A formal query language associated with the relational model. Queries in ALGEBRA are composed using a collection

More information

Overview of the Class and Introduction to DB schemas and queries. Lois Delcambre

Overview of the Class and Introduction to DB schemas and queries. Lois Delcambre Overview of the Class and Introduction to DB schemas and queries Lois Delcambre 1 CS 386/586 Introduction to Databases Instructor: Lois Delcambre lmd@cs.pdx.edu 503 725-2405 TA: TBA Office Hours: Immediately

More information

Relational Algebra Homework 0 Due Tonight, 5pm! R & G, Chapter 4 Room Swap for Tuesday Discussion Section Homework 1 will be posted Tomorrow

Relational Algebra Homework 0 Due Tonight, 5pm! R & G, Chapter 4 Room Swap for Tuesday Discussion Section Homework 1 will be posted Tomorrow Relational Algebra R & G, Chapter 4 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 power of

More information

Chapter 3. The Relational Model. Database Systems p. 61/569

Chapter 3. The Relational Model. Database Systems p. 61/569 Chapter 3 The Relational Model Database Systems p. 61/569 Introduction The relational model was developed by E.F. Codd in the 1970s (he received the Turing award for it) One of the most widely-used data

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns) tuples (or rows) 2.2 Attribute Types The

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Relational Databases: Tuples, Tables, Schemas, Relational Algebra Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Overview

More information

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan More on SQL Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan SELECT A1, A2,, Am FROM R1, R2,, Rn WHERE C1, C2,, Ck Interpreting a Query

More information

Relational Algebra. B term 2004: lecture 10, 11

Relational Algebra. B term 2004: lecture 10, 11 Relational lgebra term 00: lecture 0, Nov, 00 asics Relational lgebra is defined on bags, rather than relations. ag or multiset allows duplicate values; but order is not significant. We can write an expression

More information

Chapter 6 The Relational Algebra and Relational Calculus

Chapter 6 The Relational Algebra and Relational Calculus Chapter 6 The Relational Algebra and Relational Calculus Fundamentals of Database Systems, 6/e The Relational Algebra and Relational Calculus Dr. Salha M. Alzahrani 1 Fundamentals of Databases Topics so

More information

Relational Algebra 1

Relational Algebra 1 Relational Algebra 1 Relational Algebra Last time: started on Relational Algebra What your SQL queries are translated to for evaluation A formal query language based on operators Rel Rel Op Rel Op Rel

More information

Faloutsos - Pavlo CMU SCS /615

Faloutsos - Pavlo CMU SCS /615 Faloutsos - Pavlo 15-415/615 Carnegie Mellon Univ. School of Computer Science 15-415/615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra Overview history concepts Formal query

More information

Overview. Carnegie Mellon Univ. School of Computer Science /615 - DB Applications. Concepts - reminder. History

Overview. Carnegie Mellon Univ. School of Computer Science /615 - DB Applications. Concepts - reminder. History Faloutsos - Pavlo 15-415/615 Carnegie Mellon Univ. School of Computer Science 15-415/615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra Overview history concepts Formal query

More information

v Conceptual Design: ER model v Logical Design: ER to relational model v Querying and manipulating data

v Conceptual Design: ER model v Logical Design: ER to relational model v Querying and manipulating data Outline Conceptual Design: ER model Relational Algebra Calculus Yanlei Diao UMass Amherst Logical Design: ER to relational model Querying and manipulating data Practical language: SQL Declarative: say

More information

Relational Model, Relational Algebra, and SQL

Relational Model, Relational Algebra, and SQL Relational Model, Relational Algebra, and SQL August 29, 2007 1 Relational Model Data model. constraints. Set of conceptual tools for describing of data, data semantics, data relationships, and data integrity

More information

MIS Database Systems Relational Algebra

MIS Database Systems Relational Algebra MIS 335 - Database Systems Relational Algebra http://www.mis.boun.edu.tr/durahim/ Ahmet Onur Durahim Learning Objectives Basics of Query Languages Relational Algebra Selection Projection Union, Intersection,

More information

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #2: The Relational Model and Relational Algebra

CS 4604: Introduction to Database Management Systems. B. Aditya Prakash Lecture #2: The Relational Model and Relational Algebra CS 4604: Introduction to Database Management Systems B. Aditya Prakash Lecture #2: The Relational Model and Relational Algebra Course Outline Weeks 1 4: Query/ Manipulation Languages and Data Modeling

More information

Relational Algebra 1

Relational Algebra 1 Relational Algebra 1 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports simple, powerful QLs: Strong formal foundation based

More information

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity COS 597A: Principles of Database and Information Systems Relational model continued Understanding how to use the relational model 1 with as weak entity folded into folded into branches: (br_, librarian,

More information

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and Chapter 6 The Relational Algebra and Relational Calculus Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Outline Unary Relational Operations: SELECT and PROJECT Relational

More information

Relational Query Languages

Relational Query Languages Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports simple, powerful, declarative QLs with precise semantics: Strong formal foundation

More information

Relational Algebra and SQL

Relational Algebra and SQL Relational Algebra and SQL Computer Science E-66 Harvard University David G. Sullivan, Ph.D. Example Domain: a University We ll use relations from a university database. four relations that store info.

More information

1 Relational Data Model

1 Relational Data Model Prof. Dr.-Ing. Wolfgang Lehner INTELLIGENT DATABASE GROUP 1 Relational Data Model What is in the Lecture? 1. Database Usage Query Programming Design 2 Relational Model 3 The Relational Model The Relation

More information

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions. COSC 304 Introduction to Database Systems Relational Model and Algebra Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was

More information

CSCC43H: Introduction to Databases. Lecture 3

CSCC43H: Introduction to Databases. Lecture 3 CSCC43H: Introduction to Databases Lecture 3 Wael Aboulsaadat Acknowledgment: these slides are partially based on Prof. Garcia-Molina & Prof. Ullman slides accompanying the course s textbook. CSCC43: Introduction

More information

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13 CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible

More information

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board Note: Slides are posted on the class website, protected by a password written on the board Reading: see class home page www.cs.umb.edu/cs630. Relational Algebra CS430/630 Lecture 2 Slides based on Database

More information

CSC 261/461 Database Systems Lecture 13. Fall 2017

CSC 261/461 Database Systems Lecture 13. Fall 2017 CSC 261/461 Database Systems Lecture 13 Fall 2017 Announcement Start learning HTML, CSS, JavaScript, PHP + SQL We will cover the basics next week https://www.w3schools.com/php/php_mysql_intro.asp Project

More information

Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune

Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune Relational Algebra Mr. Prasad Sawant MACS College Pune MACS College Relational Algebra Tuple - a collection of attributes which describe some real world entity. Attribute - a real world role played by

More information

CMPT 354: Database System I. Lecture 5. Relational Algebra

CMPT 354: Database System I. Lecture 5. Relational Algebra CMPT 354: Database System I Lecture 5. Relational Algebra 1 What have we learned Lec 1. DatabaseHistory Lec 2. Relational Model Lec 3-4. SQL 2 Why Relational Algebra matter? An essential topic to understand

More information

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall Relational Algebra Study Chapter 4.1-4.2 Comp 521 Files and Databases Fall 2010 1 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model

More information

Lecture 16. The Relational Model

Lecture 16. The Relational Model Lecture 16 The Relational Model Lecture 16 Today s Lecture 1. The Relational Model & Relational Algebra 2. Relational Algebra Pt. II [Optional: may skip] 2 Lecture 16 > Section 1 1. The Relational Model

More information

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1 Relational Algebra [R&G] Chapter 4, Part A CS4320 1 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports simple, powerful QLs:

More information

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Database Management Systems Chapter 4 Relational Algebra Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Formal Relational Query Languages Two mathematical Query Languages form the basis

More information

Modeling access. Relational query languages. Queries. Selection σ P (R) Relational model: Relational algebra

Modeling access. Relational query languages. Queries. Selection σ P (R) Relational model: Relational algebra COS 597A: Principles of Database and Information Systems Relational model: Relational algebra Modeling access Have looked at modeling information as data + structure Now: how model access to data in relational

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

Relational Databases. Relational Databases. Extended Functional view of Information Manager. e.g. Schema & Example instance of student Relation

Relational Databases. Relational Databases. Extended Functional view of Information Manager. e.g. Schema & Example instance of student Relation Relational Databases Relational Databases 1 Relational Model of Data 2 Relational Algebra (and connection to Datalog) Relational database: a set of relations/tables Relation schema : specifies name of

More information

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

CIS 330: Applied Database Systems. ER to Relational Relational Algebra CIS 330: Applied Database Systems ER to Relational Relational Algebra 1 Logical DB Design: ER to Relational Entity sets to tables: ssn name Employees lot CREATE TABLE Employees (ssn CHAR(11), name CHAR(20),

More information

Relational Algebra. Relational Query Languages

Relational Algebra. Relational Query Languages Relational Algebra π CS 186 Fall 2002, Lecture 7 R & G, Chapter 4 By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect,

More information

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra Note: Slides are posted on the class website, protected by a password written on the board Reading: see class home page www.cs.umb.edu/cs630. Relational Algebra CS430/630 Lecture 2 Relational Query Languages

More information

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications Faloutsos Lecture#6: Rel. model - SQL part1 General Overview - rel. model Formal query languages rel algebra and calculi Commercial

More information

Relational Model & Algebra. Announcements (Thu. Aug. 27) Relational data model. CPS 116 Introduction to Database Systems

Relational Model & Algebra. Announcements (Thu. Aug. 27) Relational data model. CPS 116 Introduction to Database Systems Relational Model & Algebra CPS 116 Introduction to Database Systems Announcements (Thu. Aug. 27) 2 Homework #1 will be assigned next Tuesday Office hours: see also course website Jun: LSRC D327 Tue. 1.5

More information

Relational Query Languages. Relational Algebra. Preliminaries. Formal Relational Query Languages. Relational Algebra: 5 Basic Operations

Relational Query Languages. Relational Algebra. Preliminaries. Formal Relational Query Languages. Relational Algebra: 5 Basic Operations Relational Algebra R & G, Chapter 4 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 power of

More information

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #3: SQL and Rela2onal Algebra- - - Part 1

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #3: SQL and Rela2onal Algebra- - - Part 1 CS 4604: Introduc0on to Database Management Systems B. Aditya Prakash Lecture #3: SQL and Rela2onal Algebra- - - Part 1 Reminder: Rela0onal Algebra Rela2onal algebra is a nota2on for specifying queries

More information

Experimenting with bags (tables and query answers with duplicate rows):

Experimenting with bags (tables and query answers with duplicate rows): January 16, 2013 Activities CS 386/586 Experimenting with bags (tables and query answers with duplicate rows): Write an SQL query (and run it against the sailors database) that does the following: 1. List

More information

The SQL data-definition language (DDL) allows defining :

The SQL data-definition language (DDL) allows defining : Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries

More information

DATABASE DESIGN I - 1DL300

DATABASE DESIGN I - 1DL300 DATABASE DESIGN I - 1DL300 Spring 2013 An Introductory Course on Database Systems http://www.it.uu.se/edu/course/homepage/dbastekn/vt13/ Uppsala Database Laboratory Department of Information Technology,

More information

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until Databases Relational Model, Algebra and operations How do we model and manipulate complex data structures inside a computer system? Until 1970.. Many different views or ways of doing this Could use tree

More information

Review: Where have we been?

Review: Where have we been? SQL Basic Review Query languages provide 2 key advantages: Less work for user asking query More opportunities for optimization Algebra and safe calculus are simple and powerful models for query languages

More information

Relational Query Languages

Relational Query Languages 1 ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION JING YANG 2010 FALL Class 9: The Relational Algebra and Relational Calculus Relational Query Languages 2 Query languages: Allow manipulation and retrieval

More information

Ian Kenny. November 28, 2017

Ian Kenny. November 28, 2017 Ian Kenny November 28, 2017 Introductory Databases Relational Algebra Introduction In this lecture we will cover Relational Algebra. Relational Algebra is the foundation upon which SQL is built and is

More information

Database Technology Introduction. Heiko Paulheim

Database Technology Introduction. Heiko Paulheim Database Technology Introduction Outline The Need for Databases Data Models Relational Databases Database Design Storage Manager Query Processing Transaction Manager Introduction to the Relational Model

More information

EECS 647: Introduction to Database Systems

EECS 647: Introduction to Database Systems EECS 647: Introduction to Database Systems Instructor: Luke Huan Spring 2009 Stating Points A database A database management system A miniworld A data model Conceptual model Relational model 2/24/2009

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Non è possibile visualizzare l'immagine. Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns)

More information

Relational Model & Algebra. Announcements (Tue. Sep. 3) Relational data model. CompSci 316 Introduction to Database Systems

Relational Model & Algebra. Announcements (Tue. Sep. 3) Relational data model. CompSci 316 Introduction to Database Systems Relational Model & Algebra CompSci 316 Introduction to Database Systems Announcements (Tue. Sep. 3) Homework #1 has been posted Sign up for Gradiance now! Windows Azure passcode will be emailed soon sign

More information

Agenda. Database Systems. Session 5 Main Theme. Relational Algebra, Relational Calculus, and SQL. Dr. Jean-Claude Franchitti

Agenda. Database Systems. Session 5 Main Theme. Relational Algebra, Relational Calculus, and SQL. Dr. Jean-Claude Franchitti Database Systems Session 5 Main Theme Relational Algebra, Relational Calculus, and SQL Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences

More information

Chapter 2 Introduction to Relational Models

Chapter 2 Introduction to Relational Models CMSC 461, Database Management Systems Spring 2018 Chapter 2 Introduction to Relational Models These slides are based on Database System Concepts book and slides, 6th edition, and the 2009 CMSC 461 slides

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

Database Systems. Course Administration. 10/13/2010 Lecture #4

Database Systems. Course Administration. 10/13/2010 Lecture #4 Database Systems 10/13/2010 Lecture #4 1 Course Administration Assignment #1 is due at the end of next week s class. Course slides will now have black background Printer friendly: set the printing color

More information

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1 COSC344 Database Theory and Applications σ a= c (P) S P Lecture 3 The Relational Data π A, C (H) Model COSC344 Lecture 3 1 Overview Last Lecture Database design ER modelling This Lecture Relational model

More information

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24 Databases - Relational Algebra (GF Royle, N Spadaccini 2006-2010) Databases - Relational Algebra 1 / 24 This lecture This lecture covers relational algebra which is the formal language underlying the manipulation

More information

CSEN 501 CSEN501 - Databases I

CSEN 501 CSEN501 - Databases I CSEN501 - Databases I Lecture 5: Structured Query Language (SQL) Prof. Dr. Slim slim.abdennadher@guc.edu.eg German University Cairo, Faculty of Media Engineering and Technology Structured Query Language:

More information

Relational Algebra. Relational Query Languages

Relational Algebra. Relational Query Languages Relational Algebra Davood Rafiei 1 Relational Query Languages Languages for describing queries on a relational database Three variants Relational Algebra Relational Calculus SQL Query languages v.s. programming

More information

This lecture. Projection. Relational Algebra. Suppose we have a relation

This lecture. Projection. Relational Algebra. Suppose we have a relation This lecture Databases - Relational Algebra This lecture covers relational algebra which is the formal language underlying the manipulation of relations. We follow the notation from Chapter 4 of Ramakrishnan

More information

Chapter 2 The relational Model of data. Relational algebra

Chapter 2 The relational Model of data. Relational algebra Chapter 2 The relational Model of data Relational algebra 1 Contents What is a data model? Basics of the relational model How to define? How to query? Constraints on relations 2 An algebraic query language

More information

DBMS. Relational Model. Module Title?

DBMS. Relational Model. Module Title? Relational Model Why Study the Relational Model? Most widely used model currently. DB2,, MySQL, Oracle, PostgreSQL, SQLServer, Note: some Legacy systems use older models e.g., IBM s IMS Object-oriented

More information

Chapter 6 Formal Relational Query Languages

Chapter 6 Formal Relational Query Languages CMSC 461, Database Management Systems Spring 2018 Chapter 6 Formal Relational Query Languages These slides are based on Database System Concepts book and slides, 6th edition, and the 2009/2012 CMSC 461

More information

Introduction to Data Management CSE 344. Lectures 8: Relational Algebra

Introduction to Data Management CSE 344. Lectures 8: Relational Algebra Introduction to Data Management CSE 344 Lectures 8: Relational Algebra CSE 344 - Winter 2016 1 Announcements Homework 3 is posted Microsoft Azure Cloud services! Use the promotion code you received Due

More information

CS 377 Database Systems

CS 377 Database Systems CS 377 Database Systems Relational Algebra and Calculus Li Xiong Department of Mathematics and Computer Science Emory University 1 ER Diagram of Company Database 2 3 4 5 Relational Algebra and Relational

More information

Database Management System. Relational Algebra and operations

Database Management System. Relational Algebra and operations Database Management System Relational Algebra and operations Basic operations: Selection ( ) Selects a subset of rows from relation. Projection ( ) Deletes unwanted columns from relation. Cross-product

More information

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No. # 3 Relational Model Hello everyone, we have been looking into

More information

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query

More information

CS 582 Database Management Systems II

CS 582 Database Management Systems II Review of SQL Basics SQL overview Several parts Data-definition language (DDL): insert, delete, modify schemas Data-manipulation language (DML): insert, delete, modify tuples Integrity View definition

More information

Introduction to Data Management CSE 344. Lectures 8: Relational Algebra

Introduction to Data Management CSE 344. Lectures 8: Relational Algebra Introduction to Data Management CSE 344 Lectures 8: Relational Algebra CSE 344 - Winter 2017 1 Announcements Homework 3 is posted Microsoft Azure Cloud services! Use the promotion code you received Due

More information

Relational Algebra. Procedural language Six basic operators

Relational Algebra. Procedural language Six basic operators Relational algebra Relational Algebra Procedural language Six basic operators select: σ project: union: set difference: Cartesian product: x rename: ρ The operators take one or two relations as inputs

More information

Relational Algebra and SQL

Relational Algebra and SQL Relational Algebra and SQL Relational Algebra. This algebra is an important form of query language for the relational model. The operators of the relational algebra: divided into the following classes:

More information

Basic operators: selection, projection, cross product, union, difference,

Basic operators: selection, projection, cross product, union, difference, CS145 Lecture Notes #6 Relational Algebra Steps in Building and Using a Database 1. Design schema 2. Create schema in DBMS 3. Load initial data 4. Repeat: execute queries and updates on the database Database

More information

Relational Algebra Part I. CS 377: Database Systems

Relational Algebra Part I. CS 377: Database Systems Relational Algebra Part I CS 377: Database Systems Recap of Last Week ER Model: Design good conceptual models to store information Relational Model: Table representation with structures and constraints

More information

The Relational Algebra

The Relational Algebra The Relational Algebra Relational Algebra Relational algebra is the basic set of operations for the relational model These operations enable a user to specify basic retrieval requests (or queries) 27-Jan-14

More information

Relational algebra. Iztok Savnik, FAMNIT. IDB, Algebra

Relational algebra. Iztok Savnik, FAMNIT. IDB, Algebra Relational algebra Iztok Savnik, FAMNIT Slides & Textbook Textbook: Raghu Ramakrishnan, Johannes Gehrke, Database Management Systems, McGraw-Hill, 3 rd ed., 2007. Slides: From Cow Book : R.Ramakrishnan,

More information

Optimization Overview

Optimization Overview Lecture 17 Optimization Overview Lecture 17 Lecture 17 Today s Lecture 1. Logical Optimization 2. Physical Optimization 3. Course Summary 2 Lecture 17 Logical vs. Physical Optimization Logical optimization:

More information

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems CompSci 516 Data Intensive Computing Systems Lecture 2 SQL Instructor: Sudeepa Roy Duke CS, Spring 2016 CompSci 516: Data Intensive Computing Systems 1 Announcement If you are enrolled to the class, but

More information

CS317 File and Database Systems

CS317 File and Database Systems CS317 File and Database Systems Lecture 3 Relational Model & Languages Part-1 September 7, 2018 Sam Siewert More Embedded Systems Summer - Analog, Digital, Firmware, Software Reasons to Consider Catch

More information

CMP-3440 Database Systems

CMP-3440 Database Systems CMP-3440 Database Systems Relational DB Languages Relational Algebra, Calculus, SQL Lecture 05 zain 1 Introduction Relational algebra & relational calculus are formal languages associated with the relational

More information

Mahathma Gandhi University

Mahathma Gandhi University Mahathma Gandhi University BSc Computer science III Semester BCS 303 OBJECTIVE TYPE QUESTIONS Choose the correct or best alternative in the following: Q.1 In the relational modes, cardinality is termed

More information

Basant Group of Institution

Basant Group of Institution Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of

More information

QQ Group

QQ Group QQ Group: 617230453 1 Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join 2 Generalized Projection Extends the projection operation by allowing arithmetic functions

More information

Section 2.2: Relational Databases

Section 2.2: Relational Databases Page 1 Section 2.2: Relational Databases Databases A database is a set of records that can be manipulated by a computer. Database management systems allow users of the system to perform a variety of operations,

More information

Administration Naive DBMS CMPT 454 Topics. John Edgar 2

Administration Naive DBMS CMPT 454 Topics. John Edgar 2 Administration Naive DBMS CMPT 454 Topics John Edgar 2 http://www.cs.sfu.ca/coursecentral/454/johnwill/ John Edgar 4 Assignments 25% Midterm exam in class 20% Final exam 55% John Edgar 5 A database stores

More information

CS 377 Database Systems

CS 377 Database Systems CS 377 Database Systems Relational Data Model Li Xiong Department of Mathematics and Computer Science Emory University 1 Outline Relational Model Concepts Relational Model Constraints Relational Database

More information

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages Why Study the Relational Model? The Relational Model Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Legacy systems in older models E.G., IBM s IMS Recent competitor: object-oriented

More information

CS3DB3/SE4DB3/SE6DB3 TUTORIAL

CS3DB3/SE4DB3/SE6DB3 TUTORIAL CS3DB3/SE4DB3/SE6DB3 TUTORIAL Xiao Jiao Wang Feb 25, 2015 Relational Algebra IMPORTANT: relational engines work on bags, no set!!! Union, intersection, and difference Union: Intersection: Difference: Note:

More information

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects.

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects. Set Theory Set theory is a branch of mathematics that studies sets. Sets are a collection of objects. Often, all members of a set have similar properties, such as odd numbers less than 10 or students in

More information

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1

COURSE OVERVIEW THE RELATIONAL MODEL. CS121: Relational Databases Fall 2017 Lecture 1 COURSE OVERVIEW THE RELATIONAL MODEL CS121: Relational Databases Fall 2017 Lecture 1 Course Overview 2 Introduction to relational database systems Theory and use of relational databases Focus on: The Relational

More information

CMPT 354: Database System I. Lecture 2. Relational Model

CMPT 354: Database System I. Lecture 2. Relational Model CMPT 354: Database System I Lecture 2. Relational Model 1 Outline An overview of data models Basics of the Relational Model Define a relational schema in SQL 2 Outline An overview of data models Basics

More information