Database System Concepts

Size: px
Start display at page:

Download "Database System Concepts"

Transcription

1 s Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan. Chapter 2: Model Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2009/2010

2 Outline 1 s s

3 Outline 1 s s

4 Example of a Relation s customer_name customer_street customer_city Jones Main Harrison Smith North Rye Curry North Rye Lindsay Park Pittsfield

5 Basic Structure s Formally, given sets D 1, D 2,..., D n, a relation r is a subset of D 1 D 2 D n Thus, a relation is a set of n-tuples (a 1,a 2,...,a n ), where each a i D i Example: If Then customer name ={Jones, Smith, Curry, Lindsay} customer street ={Main, North, Park} customer city ={Harrison, Rye, Pittsfield} r = {(Jones, Main, Harrison),(Smith, North, Rye), is a relation over (Curry, North, Rye),(Lindsay, Park, Pittsfield)} customer_name customer_street customer_city

6 Attribute Types s Each attribute of a relation has a name The set of allowed values for each attribute is called the domain attribute Attribute values are (normally) required to be atomic; that is, indivisible Note: multivalued attribute values are not atomic Note: composite attribute values are not atomic The special value null is a member of every domain The null value causes complications in the definition of many operations We shall ignore the effect of null values in our main presentation and consider their effect later

7 Relation Schema s A 1, A 2,...,A n are attributes R = (A 1, A 2,...,A n ) is a relation schema Example: Customer schema=(customer name,customer street,customer city) r(r) is a relation on the relation schema R Example: Or: customer(customer schema) customer(customer name,customer street,customer city)

8 Relation Instance s The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table attributes customer name customer street customer city Jones Main Harrison Smith North Rye Curry North Rye Lindsay Park Pittsfield (columns) tuples (rows) Order of tuples is irrelevant (tuples may be stored in an arbitrary order)

9 s A database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part information account: stores information about accounts depositor: stores information about which customer owns which account customer : stores information about customers Why not store all information as a single relation? bank(account number, balance, customer name,...)

10 The bank database s

11 Keys s Let K R K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(r) by possible r we mean a relation r that could exist in the enterprise we are modeling. Example: {customer name, customer street} and {customer name} are both superkeys of Customer, if no two customers can possibly have the same name. K is a candidate key if K is minimal Example: {customer name} is a candidate key for Customer, since it is a superkey (assuming no two customers can possibly have the same name), and no subset of it is a superkey. Primary Key is a candidate key that will be taken as the main identifier for the tuples in the relation

12 Keys in the customer Relation s Is {customer_name, customer_street, customer_city} a superkey? Is {customer_street} a candidate key? Is {customer_street, customer_city} a superkey?

13 Keys in the depositor Relation s What are the possible candidate keys?

14 Outline 1 s s

15 Reduction of Relation s Primary keys allow entity sets and relationship sets to be expressed uniformly as relation schemas that represent the contents database. A database which conforms to an E-R diagram can be represented by a collection of schemas. For each entity set and relationship set there is a unique schema that is assigned the name corresponding entity set or relationship set. Each schema has a number of columns (generally corresponding to attributes), which have unique names.

16 Representing Strong Entity Sets as s A strong entity set reduces to a schema with the same attributes. customer(costumer id, costumer name, costumer street, costumer city)

17 Representing Weak Entity Sets as s A weak entity set becomes a table that includes a column for the primary key identifying strong entity set payment(loan number, payment number, payment date, payment amount)

18 Representing Relationship Sets as s A many-to-many relationship set is represented as a schema with attributes for the primary keys two participating entity sets, and any descriptive attributes of the relationship set. borrower(customer id, loan number) What about a n-ary relationship?

19 Representing Relationship Sets as s Many-to-one and one-to-many relationship sets can be represented with attributes for the primary keys two participating entity sets, using the attribute on the many side as primary key. borrower(customer id, loan number) For one-to-one relationship sets, either side can be chosen to act as the many side

20 Representing Relationship Sets as s Many-to-one and one-to-many relationship sets that are total on the many-side can be represented by adding an extra attribute to the many side, containing the primary key one side customer(costumer id, costumer name, costumer street, costumer city, loan number)

21 Composite and Multivalued Attributes s Composite attributes are flattened out by creating a separate attribute for each component attribute A multivalued attribute of an entity is represented by a separate schema customer(costumer id, first name, last name,...) phone numbers(costumer id, phone number)

22 Representing Specialization as - Method 1 s Form a schema for the higher-level entity Form a schema for each lower-level entity set, include primary key of higher-level entity set and local attributes person(person id, name, street, city) employee(person id, salary) customer(person id, credit rating) Drawback: getting information about an employee requires accessing two relations

23 Representing Specialization as - Method 2 Form a schema for each entity set with all local and inherited attributes s person(person id, name, street, city) employee(person id, name, street, city, salary) customer(person id, name, street, city, credit rating) If specialization is total, the schema for the generalized entity set (person) is not required to store information Drawback: street and city may be stored redundantly for people who are both customers and employees

24 Corresponding to Aggregation s To represent aggregation, create a schema containing primary key aggregated relationship, the primary key associated entity set any descriptive attributes manages(manager name, employee id, branch name, title) Schema works on is redundant provided we are willing to store null values for attribute manager name manages

25 Outline 1 s s

26 Query Languages s Language in which user requests information from the database. Categories of languages Procedural Non-procedural, or declarative Pure languages: algebra Tuple relational calculus Domain relational calculus Pure languages form underlying basis of query languages that people use.

27 s Procedural language Six basic operators select: σ project: π union: set difference: Cartesian product: rename: ρ The operators take one or two relations as inputs and produce a new relation as a result.

28 The Select Operation s Notation: σ p (r) p is called the selection predicate Defined as: σ p (r) = {t t r and p(t)} Where p is a formula in propositional calculus consisting of terms connected by : (and), (or), (not) Each term is one of: < attribute > op < attribute > or < constant > where op is one of: =,, >,, <, Example of selection: σ branch name= Perryridge (account)

29 The Select Operation - Example s σ branch name= Perryridge (account)

30 The Select Operation - Example s Relation r σ A=B D>5 (r) =? A B C D a a 1 7 a b 5 7 b b 12 3 b b 23 10

31 The Select Operation - Example s Relation r σ A=B D>5 (r) =? A B C D a a 1 7 a b 5 7 b b 12 3 b b 23 10

32 The Select Operation - Example s Relation r σ A=B D>5 (r) =? A B C D a a 1 7 a b 5 7 b b 12 3 b b A B C D a a 1 7 b b 23 10

33 The Project Operation s Notation: π A1,A 2,...,A k (r) where A 1, A 2 are attribute names and r is a relation name. The result is defined as the relation of k columns obtained by erasing the columns that are not listed Duplicate rows removed from result, since relations are sets Example: To eliminate the branch name attribute of account π account number,balance (account)

34 The Project Operation - Example s π account number,balance (account) =?

35 The Project Operation - Example s Relation r π A,C (r) =? A B C a 10 1 a 20 1 b 30 1 b 40 2

36 The Project Operation - Example s Relation r π A,C (r) =? A B C a 10 1 a 20 1 b 30 1 b 40 2

37 The Project Operation - Example s Relation r π A,C (r) =? A A B C a 10 1 a 20 1 b 30 1 b 40 2 C a 1 a 1 b 1 b 2

38 The Project Operation - Example s Relation r π A,C (r) =? A A B C a 10 1 a 20 1 b 30 1 b 40 2 C a 1 a 1 b 1 b 2 = A C a 1 b 1 b 2

39 The Union Operation s Notation: Defined as: For r s to be valid: r s r s = {t t r or t s} 1 r and s must have the same arity (same number of attributes) 2 The attribute domains must be compatible (example: 2nd column of r deals with the same type of values as does the 2nd column of s) Example: to find all customers with either an account or a loan π customer name (depositor) π customer name (borrower)

40 The Union Operation - Example s π customer name (depositor) =? π customer name (borrower) =? π customer name (depositor) π customer name (borrower) =? Incorrect: π account number (depositor) π customer name (borrower)

41 The Union Operation - Example s π customer name (depositor) =? π customer name (borrower) =? π customer name (depositor) π customer name (borrower) =? Incorrect: π account number (depositor) π customer name (borrower)

42 The Union Operation - Example Relations r and s s r s =? r = A B a 1 a 2 b 1 s = A B a 2 b 3

43 The Union Operation - Example Relations r and s s r s =? r = A B a 1 a 2 b 1 s = A B a 2 b 3

44 The Union Operation - Example Relations r and s s r s =? r = A B a 1 a 2 b 1 A B a 1 a 2 b 1 b 3 s = A B a 2 b 3

45 The Set Difference Operation s Notation: Defined as: r s r s = {t t r and t s} For r s to be valid: 1 r and s must have the same arity 2 The attribute domains must be compatible Example: to find all customers with an account but not a loan π customer name (depositor) π customer name (borrower)

46 The Set Difference Operation - Example s π customer name (depositor) =? π customer name (borrower) =? π customer name (depositor) π customer name (borrower) =? Incorrect: π account number (depositor) π customer name (borrower)

47 The Set Difference Operation - Example s π customer name (depositor) =? π customer name (borrower) =? π customer name (depositor) π customer name (borrower) =? Incorrect: π account number (depositor) π customer name (borrower)

48 The Set Difference Operation - Example s Relations r and s A r s =? r = B a 1 a 2 b 1 s = A B a 2 b 3

49 The Set Difference Operation - Example s Relations r and s A r s =? r = B a 1 a 2 b 1 s = A B a 2 b 3

50 The Set Difference Operation - Example s Relations r and s A r s =? r = B a 1 a 2 b 1 A B a 1 b 1 s = A B a 2 b 3

51 The Cartesian Product Operation s Notation: Defined as: r s r s = {tq t r and q s} Assume that attributes of r(r) and s(s) are disjoint. (That is, R S = ). If attributes of r(r) and s(s) are not disjoint, then renaming must be used.

52 The Cartesian Product Operation - Example s Relations r and s r s =? r = A B a 1 b 2 s = C D E a 10 x b 10 x b 20 y c 10 y

53 The Cartesian Product Operation - Example s Relations r and s r s =? r = A B a 1 b 2 s = C D E a 10 x b 10 x b 20 y c 10 y

54 The Cartesian Product Operation - Example s Relations r and s r s =? r = A B a 1 b 2 s = A B C D E a 1 a 10 x a 1 b 10 x a 1 b 20 y a 1 c 10 y b 2 a 10 x b 2 b 10 x b 2 b 20 y b 2 c 10 y C D E a 10 x b 10 x b 20 y c 10 y

55 The Rename Operation s Allows us to name, and therefore to refer to, the results of relational-algebra expressions. Allows us to refer to a relation by more than one name. Example: ρ X (E) returns the expression E under the name X If a relational-algebra expression E has arity n, then ρ X(A1,A 2,...,A n)(e) returns the result of expression E under the name X, and with the attributes renamed to A 1, A 2,..., A n. ρ dep (depositor) dep(customer name, account number) ρ dep(cn,an) (depositor) dep(cn, an)

56 Operation Composition s Can build expressions using multiple operations Example: σ A=C (r s) A B C D E a 1 a 10 x a 1 b 10 x a 1 b 20 y 1 r s a 1 c 10 y b 2 a 10 x b 2 b 10 x b 2 b 20 y b 2 c 10 y 2 σ A=C 3 σ A=C (r s) A B C D E a 1 a 10 x b 2 b 10 x b 2 b 20 y

57 Operation Composition s Can build expressions using multiple operations Example: σ A=C (r s) A B C D E a 1 a 10 x a 1 b 10 x a 1 b 20 y 1 r s a 1 c 10 y b 2 a 10 x b 2 b 10 x b 2 b 20 y b 2 c 10 y 2 σ A=C 3 σ A=C (r s) A B C D E a 1 a 10 x b 2 b 10 x b 2 b 20 y

58 Operation Composition s Can build expressions using multiple operations Example: σ A=C (r s) A B C D E a 1 a 10 x a 1 b 10 x a 1 b 20 y 1 r s a 1 c 10 y b 2 a 10 x b 2 b 10 x b 2 b 20 y b 2 c 10 y 2 σ A=C 3 σ A=C (r s) A B C D E a 1 a 10 x b 2 b 10 x b 2 b 20 y

59 Operation Composition s Can build expressions using multiple operations Example: σ A=C (r s) A B C D E a 1 a 10 x a 1 b 10 x a 1 b 20 y 1 r s a 1 c 10 y b 2 a 10 x b 2 b 10 x b 2 b 20 y b 2 c 10 y 2 σ A=C 3 σ A=C (r s) A B C D E a 1 a 10 x b 2 b 10 x b 2 b 20 y

60 Operation Composition s Can build expressions using multiple operations Example: σ A=C (r s) A B C D E a 1 a 10 x a 1 b 10 x a 1 b 20 y 1 r s a 1 c 10 y b 2 a 10 x b 2 b 10 x b 2 b 20 y b 2 c 10 y 2 σ A=C 3 σ A=C (r s) A B C D E a 1 a 10 x b 2 b 10 x b 2 b 20 y

61 Outline 1 s s

62 s We define additional operations that do not add any power to the relational algebra, but that simplify common queries. Set intersection: Natural join: Division: Assignment:

63 The Set Intersection Operation s Notation: Defined as: r s r s = {t t r and t s} Note: r s = r (r s) For r s to be valid: 1 r and s must have the same arity 2 The attribute domains must be compatible Example: to find all customers with both an account and a a loan π customer name (depositor) π customer name (borrower)

64 The Set Intersection Operation - Example s Relations r and s A r = B a 1 a 2 b 1 s = A B a 2 b 3 r s =?

65 The Set Intersection Operation - Example s Relations r and s A r = B a 1 a 2 b 1 s = A B a 2 b 3 r s =?

66 The Set Intersection Operation - Example s Relations r and s A r = B a 1 a 2 b 1 s = A B a 2 b 3 r s =? A B a 2

67 The Natural Join Operation s Example Notation: r s Let r and s be relations on schemas R and S respectively. Then, r s is a relation on schema R S obtained as follows: Consider each pair of tuples t r from r and t s from s If t r and t s have the same value on each attributes in R S, add a tuple t to the result, where t has the same value as t r on r t has the same value as t s on s R = (A,B,C,D), S = (E,B,D) Result schema = (A,B,C,D,E) r s = π r.a,r.b,r.c,r.d,s.e (σ r.b=s.b r.d=s.d (r s))

68 The Natural Join Operation - Example Relations r and s A B C D B D E s r = a 1 a x b 2 c x c 4 b y a 1 c x d 2 b y s = 1 x a 3 x b 1 x c 2 y d 3 y e r s =?

69 The Natural Join Operation - Example Relations r and s A B C D B D E s r = a 1 a x b 2 c x c 4 b y a 1 c x d 2 b y s = 1 x a 3 x b 1 x c 2 y d 3 y e r s =?

70 The Natural Join Operation - Example s Relations r and s A B C D r = r s =? a 1 a x b 2 c x c 4 b y a 1 c x d 2 b y s = A B C D E a 1 a x a a 1 a x c a 1 c x a a 1 c x c d 2 b y d B D E 1 x a 3 x b 1 x c 2 y d 3 y e

71 The Division Operation s Notation: r s Let r and s be relations on schemas R and S respectively, where R = (A 1,...,A m,b 1,...,B n ) S = (B 1,...,B n ) Then, r s is a relation on schema R S obtained, such that: r s = {t t π R S (t) u s (tu r)} Where tu means the concatenation of tuples t and u to produce a single tuple Note: r s = π R S (r) π R S ((π R S (r) s) π R S,S (r))

72 The Division Operation - Example Relations r and s A B s r s =? r = a 1 a 2 a 3 b 1 c 1 d 1 d 3 d 4 e 6 e 1 b 2 s = B 1 2

73 The Division Operation - Example Relations r and s A B s r s =? r = a 1 a 2 a 3 b 1 c 1 d 1 d 3 d 4 e 6 e 1 b 2 s = B 1 2

74 The Division Operation - Example Relations r and s A B s r s =? r = a 1 a 2 a 3 b 1 c 1 d 1 d 3 d 4 e 6 e 1 b 2 A a b s = B 1 2

75 Another Division Example Relations r and s A B C D E s r = r s =? a x a x 1 a x c x 1 a x c y 1 b x c x 1 b x c y 3 c x c x 1 c x c y 1 c x b y 1 s = D E x 1 y 1

76 Another Division Example Relations r and s A B C D E s r = r s =? a x a x 1 a x c x 1 a x c y 1 b x c x 1 b x c y 3 c x c x 1 c x c y 1 c x b y 1 s = D E x 1 y 1

77 Another Division Example Relations r and s A B C D E s r = r s =? a x a x 1 a x c x 1 a x c y 1 b x c x 1 b x c y 3 c x c x 1 c x c y 1 c x b y 1 A B C a x c c x c s = D E x 1 y 1

78 The Assignement Operation s The assignment operation ( ) provides a convenient way to express complex queries. Write query as a sequential program consisting of a series of assignmets followed by an expression whose value is displayed as a result query. Assignment must always be made to a temporary relation variable. Example: write r s as temp1 π R S (r) temp2 π R S ((temp1 s) π R S,S (r)) result = temp1 temp2 The result to the right is assigned to the relation variable on the left May use variable in subsequent expressions.

79 Outline 1 s s

80 s Generalized projection Aggregate functions Outer join

81 Generalized Projection s Example Extends the projection operation by allowing arithmetic functions to be used in the projection list π F1,F 2,...,F n (E) E is any relational-algebra expression Each of F 1, F 2,...,F n are are arithmetic expressions involving constants and attributes in the schema of E. Given relation credit info(customer name, limit, credit balance) find how much more each person can spend. π customer name,limit credit balance (credit info)

82 Generalized Projection - Example s Relation r π A,C 10 (r) =? A B C a 10 1 a 20 1 b 30 1 b 40 2

83 Generalized Projection - Example s Relation r π A,C 10 (r) =? A B C a 10 1 a 20 1 b 30 1 b 40 2

84 Generalized Projection - Example s Relation r π A,C 10 (r) =? A B C a 10 1 a 20 1 b 30 1 b 40 2 A C*10 a 10 b 10 b 20

85 Aggregate Functions and s Aggregation function takes a collection of values and returns a single value as a result. avg: average value min: minimum value max: maximum value sum: sum of values count: number of values Aggregate operation in relational algebra G 1,G 2,...,G n G F1 (A 1 ),F 2 (A 2 ),...,F n(a n)(e) E is any relational-algebra expression G 1,G 2...,G n is a list of attributes on which to group (can be empty) Each F i is an aggregate function Each A i is an attribute name

86 Aggregate Operation - Example s Relation r G sum(c) (r) =? A B C a a 7 a b 7 b b 3 b b 10

87 Aggregate Operation - Example s Relation r G sum(c) (r) =? A B C a a 7 a b 7 b b 3 b b 10

88 Aggregate Operation - Example s Relation r G sum(c) (r) =? A B C a a 7 a b 7 b b 3 b b 10 sum(c) 27

89 Aggregate Operation - Example s Relation account grouped by branch name branch name account number balance Perryridge A Perryridge A Brighton A Brighton A Redwood A

90 Aggregate Operation - Example s Relation account grouped by branch name branch name account number balance Perryridge A Perryridge A Brighton A Brighton A Redwood A branch nameg sum(balance) (account)

91 Aggregate Operation - Example s Relation account grouped by branch name branch name account number balance Perryridge A Perryridge A Brighton A Brighton A Redwood A branch nameg sum(balance) (account) branch name sum(balance) Perryridge 1300 Brighton 1500 Redwood 700

92 Aggregate Functions (cont.) s Result of aggregation does not have a name Can use rename operation to give it a name For convenience, we permit renaming as part of aggregate operation branch nameg sum(balance) as sum balance (account) branch name sum balance Perryridge 1300 Brighton 1500 Redwood 700

93 Outer Join s An extension join operation that avoids loss of information. Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result join. Uses null values: null signifies that the value is unknown or does not exist All comparisons involving null are (roughly speaking) false by definition. We shall study precise meaning of comparisons with nulls later

94 Outer Join - Example s Relations loan and borrower loan number branch name amount L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700 customer name loan number Jones L-170 Smith L-230 Hayes L-155

95 Outer Join - Example s Relations loan and borrower loan number branch name amount L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700 Inner join: loan borrower customer name loan number Jones L-170 Smith L-230 Hayes L-155 loan number branch name amount customer name L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith

96 Outer Join - Example s Relations loan and borrower loan number branch name amount L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700 Left outer join: loan borrower customer name loan number Jones L-170 Smith L-230 Hayes L-155 loan number branch name amount customer name L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-260 Perryridge 1700 null

97 Outer Join - Example s Relations loan and borrower loan number branch name amount L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700 Right outer join: loan borrower customer name loan number Jones L-170 Smith L-230 Hayes L-155 loan number branch name amount customer name L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-155 null null Hayes

98 Outer Join - Example Relations loan and borrower s loan number branch name amount L-170 Downtown 3000 L-230 Redwood 4000 L-260 Perryridge 1700 customer name loan number Jones L-170 Smith L-230 Hayes L-155 Full outer join: loan borrower loan number branch name amount customer name L-170 Downtown 3000 Jones L-230 Redwood 4000 Smith L-260 Perryridge 1700 null L-155 null null Hayes

99 Outline 1 s s

100 s It is possible for tuples to have a null value, denoted by null, for some ir attributes null signifies an unknown value or that a value does not exist. The result of any arithmetic expression involving null is null Aggregate functions simply ignore null values (as in SQL) For duplicate elimination and grouping, null is treated like any other value, and two nulls are assumed to be the same (as in SQL)

101 s Comparisons with null values return the special truth value: unknown x y x OR y unknown true true unknown false unknown unknown unknown unknown x y x AND y unknown true unknown unknown false false unknown unknown unknown x unknown NOT x unknown Result of select predicate is treated as false if it evaluates to unknown

102 Outline 1 s s

103 s The content database may be modified using the following operations: Deletion Insertion Updating All these operations are expressed using the assignment operator.

104 Deletion s A delete request is expressed similarly to a query, except instead of displaying tuples to the user, the selected tuples are removed from the database. Can delete only whole tuples; cannot delete values on only particular attributes A deletion is expressed in relational algebra by: r r E where r is a relation and E is a relational algebra query.

105 Deletion Examples Delete all account records in the Perryridge branch. s Delete all loan records with amount in the range of 0 to 50 Delete all accounts at branches located in Needham

106 Deletion Examples s Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) Delete all loan records with amount in the range of 0 to 50 Delete all accounts at branches located in Needham

107 Deletion Examples s Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) Delete all loan records with amount in the range of 0 to 50 Delete all accounts at branches located in Needham

108 Deletion Examples s Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham

109 Deletion Examples s Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham

110 Deletion Examples Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) s Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham r 1 σ branch city= Needham (account branch)

111 Deletion Examples Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) s Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham r 1 σ branch city= Needham (account branch) r 2 π branch name,account number,balance (r 1 )

112 Deletion Examples Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) s Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham r 1 σ branch city= Needham (account branch) r 2 π branch name,account number,balance (r 1 ) account account r 2

113 Deletion Examples Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) s Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham r 1 σ branch city= Needham (account branch) r 2 π branch name,account number,balance (r 1 ) account account r 2 r 3 π customer name,account number (r 2 depositor)

114 Deletion Examples Delete all account records in the Perryridge branch. account account σ branch name= Perryridge (account) s Delete all loan records with amount in the range of 0 to 50 loan loan σ amount 0 and amount 50 (loan) Delete all accounts at branches located in Needham r 1 σ branch city= Needham (account branch) r 2 π branch name,account number,balance (r 1 ) account account r 2 r 3 π customer name,account number (r 2 depositor) depositor depositor r 3

115 Insertion s To insert data into a relation, we either: specify a tuple to be inserted write a query whose result is a set of tuples to be inserted In relational algebra, an insertion is expressed by: r r E where r is a relation and E is a relational algebra expression. The insertion of a single tuple is expressed by letting E be a constant relation containing one tuple.

116 Insertion Examples Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. s Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account.

117 Insertion Examples s Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account account {( Perryridge, A 973, 1200)} Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account.

118 Insertion Examples s Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account account {( Perryridge, A 973, 1200)} depositor depositor {( Smith, A 973)} Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account.

119 Insertion Examples s Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account account {( Perryridge, A 973, 1200)} depositor depositor {( Smith, A 973)} Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account.

120 Insertion Examples s Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account account {( Perryridge, A 973, 1200)} depositor depositor {( Smith, A 973)} Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account. r 1 σ branch name= Perryridge (borrower loan)

121 Insertion Examples s Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account account {( Perryridge, A 973, 1200)} depositor depositor {( Smith, A 973)} Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account. r 1 σ branch name= Perryridge (borrower loan) account account π branch name,loan number,200 (r 1 )

122 Insertion Examples s Insert information in the database specifying that Smith has $1200 in account A-973 at the Perryridge branch. account account {( Perryridge, A 973, 1200)} depositor depositor {( Smith, A 973)} Provide as a gift for all loan customers in the Perryridge branch, a $200 savings account. Let the loan number serve as the account number for the new savings account. r 1 σ branch name= Perryridge (borrower loan) account account π branch name,loan number,200 (r 1 ) depositor depositor π customer name,loan number (r 1 )

123 Updating s A mechanism to change a value in a tuple without charging all values in the tuple Use the generalized projection operator to do this task r π F1,F 2,...,F n (r) Each F i is either the i-th attribute of r, if the i-th attribute is not updated, or, if the attribute is to be updated F i is an expression, involving only constants and the attributes of r, which gives the new value for the attribute

124 Updating Examples s Make interest payments by increasing all balances by 5 percent. Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent

125 Updating Examples s Make interest payments by increasing all balances by 5 percent. account π account number,branch name,balance 1.05 (account) Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent

126 Updating Examples s Make interest payments by increasing all balances by 5 percent. account π account number,branch name,balance 1.05 (account) Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent

127 Updating Examples s Make interest payments by increasing all balances by 5 percent. account π account number,branch name,balance 1.05 (account) Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent r 1 σ balance>10000 (account)

128 Updating Examples s Make interest payments by increasing all balances by 5 percent. account π account number,branch name,balance 1.05 (account) Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent r 1 σ balance>10000 (account) r 2 σ balance (account)

129 Updating Examples s Make interest payments by increasing all balances by 5 percent. account π account number,branch name,balance 1.05 (account) Pay all accounts with balances over $10,000 6 percent interest and pay all others 5 percent r 1 σ balance>10000 (account) r 2 σ balance (account) account π account number,branch name,balance 1.06 (r 1 ) π account number,branch name,balance 1.05 (r 2 )

130 s End of Chapter 2

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

More information

Chapter 3: Relational Model

Chapter 3: Relational Model Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modification of the Database

More information

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016 CS34800 Information Systems The Relational Model Prof. Walid Aref 29 August, 2016 1 Chapter: The Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational

More information

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Structure of Relational Databases! Fundamental Relational-Algebra-Operations! Additional

More information

Chapter 6: Formal Relational Query Languages

Chapter 6: Formal Relational Query Languages Chapter 6: Formal Relational Query Languages Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational

More information

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU Relational Algebra 1 Structure of Relational Databases A relational database consists of a collection of tables, each of which is assigned a unique name. A row in a table represents a relationship among

More information

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

A database can be modeled as: + a collection of entities, + a set of relationships among entities. The Relational Model Lecture 2 The Entity-Relationship Model and its Translation to the Relational Model Entity-Relationship (ER) Model + Entity Sets + Relationship Sets + Database Design Issues + Mapping

More information

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation!

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation! Chapter 3: Formal Relational Query Languages CS425 Fall 2013 Boris Glavic Chapter 3: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational Calculus Textbook:

More information

Upon completion of this Unit, students will be introduced to the following

Upon completion of this Unit, students will be introduced to the following Instructional Objectives Upon completion of this Unit, students will be introduced to the following The origins of the relational model. The terminology of the relational model. How tables are used to

More information

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

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

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

Comp 5311 Database Management Systems. 2. Relational Model and Algebra

Comp 5311 Database Management Systems. 2. Relational Model and Algebra Comp 5311 Database Management Systems 2. Relational Model and Algebra 1 Basic Concepts of the Relational Model Entities and relationships of the E-R model are stored in tables also called relations (not

More information

Relational Model. Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT)

Relational Model. Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT) 2. Relational Model Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT) Attribute Types Each attribute of a relation has a name The set of allowed values for each attribute is called the domain of the

More information

Chapter 4: SQL. Basic Structure

Chapter 4: SQL. Basic Structure Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL

More information

DATABASE TECHNOLOGY - 1MB025

DATABASE TECHNOLOGY - 1MB025 1 DATABASE TECHNOLOGY - 1MB025 Fall 2005 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-ht2005/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht05/ Kjell Orsborn Uppsala

More information

DATABASE TECHNOLOGY - 1MB025

DATABASE TECHNOLOGY - 1MB025 1 DATABASE TECHNOLOGY - 1MB025 Fall 2004 An introductory course on database systems http://user.it.uu.se/~udbl/dbt-ht2004/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht04/ Kjell Orsborn Uppsala

More information

DATABASTEKNIK - 1DL116

DATABASTEKNIK - 1DL116 1 DATABASTEKNIK - 1DL116 Spring 2004 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-vt2004/ Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala

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

Database System Concepts

Database System Concepts Chapter 14: Optimization Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan.

More information

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views

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

Database System Concepts

Database System Concepts Chapter 13: Query Processing s Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2008/2009 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth

More information

DATABASE TECHNOLOGY - 1DL124

DATABASE TECHNOLOGY - 1DL124 1 DATABASE TECHNOLOGY - 1DL124 Summer 2007 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-sommar07/ alt. http://www.it.uu.se/edu/course/homepage/dbdesign/st07/ Kjell Orsborn

More information

UNIT- II (Relational Data Model & Introduction to SQL)

UNIT- II (Relational Data Model & Introduction to SQL) Database Management System 1 (NCS-502) UNIT- II (Relational Data Model & Introduction to SQL) 2.1 INTRODUCTION: 2.1.1 Database Concept: 2.1.2 Database Schema 2.2 INTEGRITY CONSTRAINTS: 2.2.1 Domain Integrity:

More information

CSE 132A Database Systems Principles

CSE 132A Database Systems Principles CSE 132A Database Systems Principles Prof. Alin Deutsch RELATIONAL DATA MODEL Some slides are based or modified from originals by Elmasri and Navathe, Fundamentals of Database Systems, 4th Edition 2004

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

DATABASE DESIGN I - 1DL300

DATABASE DESIGN I - 1DL300 DATABASE DESIGN I - 1DL300 Spring 2011 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/vt11/ Manivasakan Sabesan Uppsala Database Laboratory Department of Information

More information

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure.

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure. SL Lecture 4 SL Chapter 4 (Sections 4.1, 4.2, 4.3, 4.4, 4.5, 4., 4.8, 4.9, 4.11) Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Modification of the Database

More information

Chapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Chapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See  for conditions on re-use Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

Chapter 3: SQL. Chapter 3: SQL

Chapter 3: SQL. Chapter 3: SQL Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

CSIT5300: Advanced Database Systems

CSIT5300: Advanced Database Systems CSIT5300: Advanced Database Systems L02: Relational Data Model Dr. Kenneth LEUNG Department of Computer Science and Engineering The Hong Kong University of Science and Technology Hong Kong SAR, China kwtleung@cse.ust.hk

More information

DATABASE DESIGN I - 1DL300

DATABASE DESIGN I - 1DL300 DATABASE DESIGN I - 1DL300 Fall 2010 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/ht10/ Manivasakan Sabesan Uppsala Database Laboratory Department of Information

More information

Chapter 2: Entity-Relationship Model

Chapter 2: Entity-Relationship Model Chapter 2: Entity-Relationship Model! Entity Sets! Relationship Sets! Design Issues! Mapping Constraints! Keys! E-R Diagram! Extended E-R Features! Design of an E-R Database Schema! Reduction of an E-R

More information

Chapter 5: Other Relational Languages

Chapter 5: Other Relational Languages Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus

More information

DATABASE TECHNOLOGY. Spring An introduction to database systems

DATABASE TECHNOLOGY. Spring An introduction to database systems 1 DATABASE TECHNOLOGY Spring 2007 An introduction to database systems Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala University, Uppsala, Sweden 2 Introduction

More information

Silberschatz, Korth and Sudarshan See for conditions on re-use

Silberschatz, Korth and Sudarshan See   for conditions on re-use Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model Chapter 6: Entity-Relationship Model Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 6: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Language 4.1 Schema Used in Examples

More information

Database Systems SQL SL03

Database Systems SQL SL03 Inf4Oec10, SL03 1/52 M. Böhlen, ifi@uzh Informatik für Ökonomen II Fall 2010 Database Systems SQL SL03 Data Definition Language Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates,

More information

Database Systems SQL SL03

Database Systems SQL SL03 Checking... Informatik für Ökonomen II Fall 2010 Data Definition Language Database Systems SQL SL03 Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates, Null Values Modification

More information

Database Systems. Answers

Database Systems. Answers Database Systems Question @ Answers Question 1 What are the most important directories in the MySQL installation? Bin Executable Data Database data Docs Database documentation Question 2 What is the primary

More information

The SQL database language Parts of the SQL language

The SQL database language Parts of the SQL language DATABASE DESIGN I - 1DL300 Fall 2011 Introduction to SQL Elmasri/Navathe ch 4,5 Padron-McCarthy/Risch ch 7,8,9 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/ht11

More information

DATABASE TECHNOLOGY. Spring An introduction to database systems

DATABASE TECHNOLOGY. Spring An introduction to database systems 1 DATABASE TECHNOLOGY Spring 2007 An introduction to database systems Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala University, Uppsala, Sweden 2 Introduction

More information

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables Entity-Relationship Modelling Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables 1 Entity Sets A enterprise can be modeled as a collection of: entities, and

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

Chapter 5: Other Relational Languages.! Query-by-Example (QBE)! Datalog

Chapter 5: Other Relational Languages.! Query-by-Example (QBE)! Datalog Chapter 5: Other Relational Languages! Query-by-Example (QBE)! Datalog 5.1 Query-by by-example (QBE)! Basic Structure! Queries on One Relation! Queries on Several Relations! The Condition Box! The Result

More information

Database System Concepts

Database System Concepts s Design Chapter 1: Introduction Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2009/2010 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth

More information

DBMS: AN INTERACTIVE TUTORIAL

DBMS: AN INTERACTIVE TUTORIAL DBMS: AN INTERACTIVE TUTORIAL Organized & Prepared By Sharafat Ibn Mollah Mosharraf 12 th Batch (05-06) Dept. of Computer Science & Engineering University of Dhaka Table of Contents INTRODUCTION TO DATABASE

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

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

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model Chapter 6: Entity-Relationship Model Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 6: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to

Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to Relation Schemas Database Design UML A database can be modeled

More information

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model Chapter 6: Entity-Relationship Model Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 6: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Data Definition! Basic Query Structure! Set Operations! Aggregate Functions! Null Values!

More information

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5 SQL QUERIES CS121: Relational Databases Fall 2017 Lecture 5 SQL Queries 2 SQL queries use the SELECT statement General form is: SELECT A 1, A 2,... FROM r 1, r 2,... WHERE P; r i are the relations (tables)

More information

Midterm Review. Winter Lecture 13

Midterm Review. Winter Lecture 13 Midterm Review Winter 2006-2007 Lecture 13 Midterm Overview 3 hours, single sitting Topics: Relational model relations, keys, relational algebra expressions SQL DDL commands CREATE TABLE, CREATE VIEW Specifying

More information

Other Relational Query Languages

Other Relational Query Languages APPENDIXC Other Relational Query Languages In Chapter 6 we presented the relational algebra, which forms the basis of the widely used SQL query language. SQL was covered in great detail in Chapters 3 and

More information

Relational Algebra 1. Week 4

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

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

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

Chapter 8: Relational Algebra

Chapter 8: Relational Algebra Chapter 8: elational Algebra Outline: Introduction Unary elational Operations. Select Operator (σ) Project Operator (π) ename Operator (ρ) Assignment Operator ( ) Binary elational Operations. Set Operators

More information

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400) 1 DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400) Spring 2008 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-vt2008/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/vt08/

More information

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

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations

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

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007 Lecture 14 of 42 E-R Diagrams, UML Notes: PS3 Notes, E-R Design Thursday, 15 February 2007 William H. Hsu Department of Computing and Information Sciences, KSU KSOL course page: http://snipurl.com/va60

More information

Simple SQL Queries (2)

Simple SQL Queries (2) Simple SQL Queries (2) Review SQL the structured query language for relational databases DDL: data definition language DML: data manipulation language Create and maintain tables CMPT 354: Database I --

More information

Chapter 6: Entity-Relationship Model

Chapter 6: Entity-Relationship Model Chapter 6: Entity-Relationship Model Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 6: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram

More information

Relational Databases

Relational Databases Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4

More information

3. Relational Data Model 3.5 The Tuple Relational Calculus

3. Relational Data Model 3.5 The Tuple Relational Calculus 3. Relational Data Model 3.5 The Tuple Relational Calculus forall quantification Syntax: t R(P(t)) semantics: for all tuples t in relation R, P(t) has to be fulfilled example query: Determine all students

More information

CMSC 424 Database design Lecture 4: Relational Model ER to Relational model. Book: Chap. 2 and 6. Mihai Pop

CMSC 424 Database design Lecture 4: Relational Model ER to Relational model. Book: Chap. 2 and 6. Mihai Pop CMSC 424 Database design Lecture 4: Relational Model ER to Relational model Book: Chap. 2 and 6 Mihai Pop Oracle accounts SQL homework next week Administrative issues Summary Entity-relationship Model

More information

7042 Datenbanken. Prof. O. Nierstrasz. Wintersemester 1997/98

7042 Datenbanken. Prof. O. Nierstrasz. Wintersemester 1997/98 7042 Datenbanken Prof. O. Nierstrasz Wintersemester 1997/98 1. 7042 Datenbanken 1 Schedule 2 What you will be expected to learn: 3 Definitions? 4 In Search of a Definition... 5 What is a Database? 6 Example

More information

Relational Model. Nisa ul Hafidhoh

Relational Model. Nisa ul Hafidhoh Relational Model Nisa ul Hafidhoh nisa@dsn.dinus.ac.id Data Model Collection of conceptual tools for describing data, data relationships, data semantics, and consistency constraints Example of Data Model

More information

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called Q.1 Short Questions Marks 1. Considering functional dependency, one in which removal from some attributes must affect dependency is called 01 A. full functional dependency B. partial dependency C. prime

More information

RELATIONAL DATA MODEL: Relational Algebra

RELATIONAL DATA MODEL: Relational Algebra RELATIONAL DATA MODEL: Relational Algebra Outline 1. Relational Algebra 2. Relational Algebra Example Queries 1. Relational Algebra A basic set of relational model operations constitute the relational

More information

CSIE30600/CSIEB0290 Database Systems Relational Algebra and Calculus 2

CSIE30600/CSIEB0290 Database Systems Relational Algebra and Calculus 2 Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational Operations Additional Relational Operations Examples of Queries in Relational Algebra

More information

Database System Concepts

Database System Concepts Chapter 4(+8): Advanced SQL Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and

More information

Outline. CSIE30600 Database Systems Relational Algebra and Calculus 2

Outline. CSIE30600 Database Systems Relational Algebra and Calculus 2 Outline Relational Algebra Unary Relational Operations Relational Algebra Operations From Set Theory Binary Relational Operations Additional Relational Operations Examples of Queries in Relational Algebra

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

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi

Lecture Notes for 3 rd August Lecture topic : Introduction to Relational Model. Rishi Barua Shubham Tripathi Lecture Notes for 3 rd August 2011 Lecture topic : Introduction to Relational Model Rishi Barua 09010141 Shubham Tripathi 09010148 Example of a relation. Attribute (Column) ID Name Department Salary (Rs)

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

UNIT 2 RELATIONAL MODEL

UNIT 2 RELATIONAL MODEL UNIT 2 RELATIONAL MODEL RELATIONAL MODEL CONCEPTS The relational Model of Data is based on the concept of a Relation. A Relation is a mathematical concept based on the ideas of sets. The strength of the

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

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

1. (a) Explain the Transaction management in a database. (b) Discuss the Query Processor of Database system structure. [8+8]

1. (a) Explain the Transaction management in a database. (b) Discuss the Query Processor of Database system structure. [8+8] Code No: R059210506 Set No. 1 1. (a) Explain the Transaction management in a database. (b) Discuss the Query Processor of Database system structure. [8+8] 2. (a) What is an unsafe query? Give an example

More information

Chapter 6: Entity-Relationship Model. E-R Diagrams

Chapter 6: Entity-Relationship Model. E-R Diagrams Chapter 6: Entity-Relationship Model A database can be modeled as: a collection of entities, relationship among entities. An entity is an object that exists and is distinguishable from other objects. Example:

More information

Intro to DB CHAPTER 6

Intro to DB CHAPTER 6 Intro to DB CHAPTER 6 DATABASE DESIGN &THEER E-R MODEL Chapter 6. Entity Relationship Model Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of

More information

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as: Chapter 2: Entity-Relationship Model Entity Sets Entity Sets Relationship Sets Design Issues Mapping Constraints Keys E-R Diagram Extended E-R Features Design of an E-R Database Schema Reduction of an

More information

ERRATA for Database System Concepts, 5 th Edition Silberschatz, Korth, and Sudarshan. March 19, 2007

ERRATA for Database System Concepts, 5 th Edition Silberschatz, Korth, and Sudarshan. March 19, 2007 ERRATA FOR FIRST PRINTING: Chapter 1 ERRATA for Database System Concepts, 5 th Edition Silberschatz, Korth, and Sudarshan March 19, 2007 Page 15, Para 1, Line 6:.. employee a set.... employ a set.. Page

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

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3

RELATIONAL ALGEBRA II. CS121: Relational Databases Fall 2017 Lecture 3 RELATIONAL ALGEBRA II CS121: Relational Databases Fall 2017 Lecture 3 Last Lecture 2 Query languages provide support for retrieving information from a database Introduced the relational algebra A procedural

More information

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers Security Authorization Authorization in SQL 6.1 Domain Constraints Integrity constraints guard against accidental

More information

Informationslogistik Unit 4: The Relational Algebra

Informationslogistik Unit 4: The Relational Algebra Informationslogistik Unit 4: The Relational Algebra 26. III. 2012 Outline 1 SQL 2 Summary What happened so far? 3 The Relational Algebra Summary 4 The Relational Calculus Outline 1 SQL 2 Summary What happened

More information

Other Query Languages II. Winter Lecture 12

Other Query Languages II. Winter Lecture 12 Other Query Languages II Winter 2006-2007 Lecture 12 Last Lecture Previously discussed tuple relational calculus Purely declarative query language Same expressive power as relational algebra Could also

More information

Example: specific person, company, event, plant

Example: specific person, company, event, plant A database can be modeled as: a collection of entities, relationship among entities. An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event,

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

RELATIONAL ALGEBRA. CS121: Relational Databases Fall 2017 Lecture 2

RELATIONAL ALGEBRA. CS121: Relational Databases Fall 2017 Lecture 2 RELATIONAL ALGEBRA CS121: Relational Databases Fall 2017 Lecture 2 Administrivia 2 First assignment will be available today Due next Thursday, October 5, 2:00 AM TAs will be decided soon Should start having

More information

Chapter 12: Query Processing

Chapter 12: Query Processing Chapter 12: Query Processing Overview Catalog Information for Cost Estimation $ Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions Transformation

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