Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Systems. DataBase System Haichang Gao, Software School, Xidian University 2 Major Content & Grade  Introduction*  The Relational Model** 

Similar presentations


Presentation on theme: "Database Systems. DataBase System Haichang Gao, Software School, Xidian University 2 Major Content & Grade  Introduction*  The Relational Model** "— Presentation transcript:

1 Database Systems

2 DataBase System Haichang Gao, Software School, Xidian University 2 Major Content & Grade  Introduction*  The Relational Model**  SQL****  Transaction Management***  Database Design (E-R)***  Database Design (Normalization)***  NoSQL **

3 DataBase System Haichang Gao, Software School, Xidian University 3 Unit 2 The Relational Model  Relational Model  Relational Algebra( 关系代数 )

4 DataBase System Haichang Gao, Software School, Xidian University 4 Relational Model  Laid down in 1969-1970 by E.F.CODD “ A Relational Model of Data for Large Shared Data Bank” C ACM 1970  Mathematical Bases ( Relational Theory)  Developed in 1980s  Most commercial DBMS are Relational

5 DataBase System Haichang Gao, Software School, Xidian University 5 Mathematical Relations  Formally, given sets D 1, D 2, …. D n, a relation r is a subset of Cartesian product( 笛卡尔积 ) D 1 × D 2 × … × D n Thus a relation( 关系 ) is a set of n-tuples (a 1, a 2, …, a n ) where a i  D i  Example: if customer-name = {Jones, Smith, Curry, Lindsay} customer-street = {Main, North, Park} customer-city = {Harrison, Rye, Pittsfield} Then r = {(Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield)} is a relation over customer-name × customer-street × customer-city.

6 DataBase System Haichang Gao, Software School, Xidian University 6 Mathematical Relations  Each attribute of a relation has a name  The set of allowed values for each attribute is called the domain (域) of the 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

7 DataBase System Haichang Gao, Software School, Xidian University 7 Mathematical Relations  A 1, A 2, …, A n are attributes  R = (A 1, A 2, …, A n ) is a relation schema( 关系模式 ) E.g. Customer-schema = (customer-name, customer-street, customer-city)  r(R) is a relation on the relation schema R E.g.customer (Customer-schema)

8 DataBase System Haichang Gao, Software School, Xidian University 8 Mathematical Relations  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  Order of tuples is irrelevant ( 元组是无序的 tuples may be stored in an arbitrary order) Jones Smith Curry Lindsay customer_name Main North Park customer_street Harrison Rye Pittsfield customer_city customer attributes (or columns) tuples (or rows)

9 DataBase System Haichang Gao, Software School, Xidian University 9 Relational Database  A Relational database consists of multiple relations  Information about an enterprise is broken up into parts, with each relation storing one part of the information  Example: The customer table stores information about customers

10 DataBase System Haichang Gao, Software School, Xidian University 10 Relational Database (b) The account table (c) The depositor table The account table stores information about accounts. The depositor table containing information about which customer owns which account  Storing all information as a single relation is NOT a good idea!

11 DataBase System Haichang Gao, Software School, Xidian University 11 Key  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).  Example: {customer_id, customer_name} and {customer_id} are both superkeys of Customer.  by “ possible r ” we mean a relation r that could exist in the enterprise we are modeling.

12 DataBase System Haichang Gao, Software School, Xidian University 12 Key  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).  K is a candidate key( 候选码 ) if K is minimal.  Example: {customer_id} is a candidate key for Customer, since it is a superkey, and no subset of it is a superkey.  {customer_name} is a candidate key also, assuming no two customers can possibly have the same name.

13 DataBase System Haichang Gao, Software School, Xidian University 13 Key  Primary key( 主码 ): The candidate key that is selected to identify tuples uniquely within the relation. And the others candidate key is called Alternate Keys( 替换码 ).  Example: for relation customer (customer_id, customer_name, customer_street, customer_city)  Candidate key : {customer_id}, {customer_name}  Primary key: {customer_id}

14 DataBase System Haichang Gao, Software School, Xidian University 14 Key  For the banking database, we have several relations to store data:  Foreign Key( 外码 ): An attribute, or set of attributes,within one relation R1 that matches the candidate key of some(possibly the same) relation R2.  Example: Attribute customer_name in table depositor is a Foreign Key references to customer_name in customer.

15 DataBase System Haichang Gao, Software School, Xidian University 15 Key  Usually, Primary Key and Foreign Key was indicated using undirected line and dashed line.  Example: Find out PK and FK of the following schema: Student(sno, sname, ssex, sbirth, sdept) Course(cno, cname, cpno, ccredit) SC(sno, cno, grade)

16 DataBase System Haichang Gao, Software School, Xidian University 16 Integrity of Relational Model  Entity integrity( 实体完整性约束 ): In a base relation, NO attribute of a primary key can be null.  Referential integrity( 参照完整性约束 ): If a foreign key exists in a relation, either the foreign key value must match a candidate key value of some tuple in its home relation( 被参照关系 ) or the foreign key value must be wholly null.  Example: customer (customer_name, customer_street, customer_city) depositor (customer_name, account_number) account (account_number, branch_name, balance)

17 DataBase System Haichang Gao, Software School, Xidian University 17 Integrity of Relational Model  Null( 空值 ): Represents a value for an attribute that is currently unknown or is not applicable for this tuple.  It is possible for tuples to have a null value, denoted by null, for some of their attributes  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)  Null value is NOT 0 of integer, NOT empty string, it is JUST NULL.

18 DataBase System Haichang Gao, Software School, Xidian University 18 Integrity of Relational Model  Comparisons with null values return the special truth value: unknown  If false was used instead of unknown, then not (A = 5  Three-valued logic using the truth value unknown:  OR: (unknown or true) = true, (unknown or false) = unknown (unknown or unknown) = unknown  AND: (true and unknown) = unknown, (false and unknown) = false, (unknown and unknown) = unknown  NOT: (not unknown) = unknown  Result of select predicate is treated as false if it evaluates to unknown

19 DataBase System Haichang Gao, Software School, Xidian University 19 Unit 2 The Relational Model  Relational Model  Relational Algebra( 关系代数 )

20 DataBase System Haichang Gao, Software School, Xidian University 20 Manipulation of Relational Model  Query Language is a Language in which user requests information from the database.  Categories of languages  Procedural( 过程化的 )  Non-procedural, or declarative( 非过程化的,声明性的 )  Mathematical languages:  Relational algebra( 关系代数 )  Tuple relational calculus( 元组演算 )  Domain relational calculus ( 域演算 )  Characteristics of Relational languages  all set-at-a-time ( 一次一集合 ) operands & results are whole tables  Closure property (封闭性) the output from one operation can become input to another.

21 DataBase System Haichang Gao, Software School, Xidian University 21 Relational Algebra  Relational algebra is a Procedural language  Basic operators  select( 选择 ):   project( 投影 ): π  union( 并 ): ∪  set difference( 集合差 ): –  Cartesian product( 笛卡尔积 ): ×  rename:   The operators take two or more relations as inputs and give a new relation as a result.

22 DataBase System Haichang Gao, Software School, Xidian University 22 Basic operators  Select Operation( 选择操作 )  Notation:  p (r)  p is called the selection predicate( 条件谓词 )  Defined as:  p (r) = {t | t  r  p(t)} Where p is a formula in propositional calculus ( 命题演算 ) consisting of terms connected by :  (and),  (or),  (not) Each term is one of: op (or ) where op is one of: =, , >, , <,  (comparison operator)  Example of selection:  branch_name= “ Perryridge ” (account)

23 DataBase System Haichang Gao, Software School, Xidian University 23 Basic operators Relation r ABCD   1 5 12 23 7 3 10  A=B  D > ‘5’ (r) ABCD   1 23 7 10  Select Operation( 选择操作 )

24 DataBase System Haichang Gao, Software School, Xidian University 24 Basic operators  Project Operation( 投影操作 )  Notation: π A1, A2, …, Ak (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: For relation account (account_number, branch_name, balance) To eliminate the branch_name attribute of account π account_number, balance (account)

25 DataBase System Haichang Gao, Software School, Xidian University 25 Basic operators  Project Operation( 投影操作 ) Relation r: ABC  10 20 30 40 11121112 AC  11121112 = AC  112112 π A,C (r)

26 DataBase System Haichang Gao, Software School, Xidian University 26 Basic operators  Union Operation( 并操作 )  Notation: r  s r union s  Defined as: r  s = {t | t  r  t  s}  For r  s to be valid: 1. r, s must have the same degree( 列数相同 ) 2. The attribute domains must be compatible ( 域相容 )  Example: find all customers with either an account or a loan π customer_name (depositor)  π customer_name (borrower)

27 DataBase System Haichang Gao, Software School, Xidian University 27 Basic operators  Union Operation( 并操作 ) Relations r, s: r  s: AB  121121 r AB  2323 s AB  12131213 The 1st column of r deals with the same type of values(domain) as does the 1st column of s,and 2nd column also, and also for all attributes.

28 DataBase System Haichang Gao, Software School, Xidian University 28 Basic operators  Difference Operation( 差操作 )  Notation: r – s r minus s  Defined as: r – s = {t | t  r  t  s}  Set differences must be taken between compatible relations.  r and s must have the same degree  attribute domains of r and s must be compatible

29 DataBase System Haichang Gao, Software School, Xidian University 29 Basic operators  Difference Operation ( 差操作 ) Relations r, s: AB  121121 r AB  2323 s r – s : AB  1111

30 DataBase System Haichang Gao, Software School, Xidian University 30 Basic operators  Cartesian-Product Operation( 笛卡尔积操作 )  Notation: r × s r times s  Defined as: r × s = {tq | t  r  q  s}  Assume that attributes of r(R) and s(S) are disjoint. (That is, R  S = , NO same attribute in R and S).  If attributes of r(R) and s(S) are not disjoint, then renaming must be used.

31 DataBase System Haichang Gao, Software School, Xidian University 31 Basic operators  Cartesian-Product Operation( 笛卡尔积操作 ) Relations r, s: r × s:r × s: AB  1111222211112222 CD  10 19 20 10 20 10 E aabbaabbaabbaabb AB  1212 r CD  20 10 E aabbaabb s

32 DataBase System Haichang Gao, Software School, Xidian University 32 Basic operators  Rename Operation( 重命名操作 )  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 degree n, then  x (A1, A2, …, An) (E) A1, A2, …., An returns the result of expression E under the name x, and with the attributes renamed to A1, A2, …., An.

33 DataBase System Haichang Gao, Software School, Xidian University 33 Example Queries  Find the largest account balance. account_ number Branch_ name balance A-101Downtown500 A-215Mianus700 A-102Perryridge400 ………… account  A1.balance >A2.balance (  A1 (account) ×  A2 (account) ) ? π A1.balance (  A1.balance < A2.balance (  A1 (account) ×  A2 (account) ) ) π balance (account) – 最小值不被选中 !

34 Database Systems

35 DataBase System Haichang Gao, Software School, Xidian University 35 Unit 2 The Relational Model  Relational Model  Relational Algebra( 关系代数 )  Relational Calculus( 关系演算 )

36 DataBase System Haichang Gao, Software School, Xidian University 36 Relational Algebra expression  A basic expression in the relational algebra consists of either one of the following:  A relation in the database  A constant relation  Let E 1 and E 2 be relational-algebra expressions; the following are all relational-algebra expressions:  E 1  E 2  E 1 – E 2  E 1 × E 2   p (E 1 ), P is a predicate on attributes in E 1  π s (E 1 ), S is a list consisting of some of the attributes in E 1   x (E 1 ), x is the new name for the result of E 1

37 DataBase System Haichang Gao, Software School, Xidian University 37 Example Queries  Banking DataBase: branch (branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) depositor (customer_name, account_number) account (account_number, branch_name, balance) borrower (customer_name, loan_number) loan (loan_number, branch_name, amount)

38 DataBase System Haichang Gao, Software School, Xidian University 38 Example Queries  Find the loan number for each loan of an amount greater than $1200. loan_numberbranch_nameamount L-11Round Hill900 L-14Downtown1500 L-15Perryridge1500 L-16Perryridge1300 L-17Downtown1000 L-23Redwood2000 L-93Mianus500 loan  amount > ‘1200’ (loan) loan_number L-14 L-15 L-16 L-23 注:除特别要求外,写查询表 达式时不需要写出结果集! π loan_number ( )

39 DataBase System Haichang Gao, Software School, Xidian University 39 Example Queries  Find the customers name who have at least one deposit of a balance greater than $700. account_ number branch_ name balance A-101Downtown500 A-215Mianus700 A-102Perryridge400 A-305Round Hill350 A-201Brighton900 A-222Redwood700 A-217Brighton750 account customer_ name account_ number HayesA-102 JohnsonA-101 JohnsonA-201 JonesA-217 LindsayA-222 SmithA-215 TurnerA-305 depositor  balance> ’ 700 ’ (account) π account_number ( ) ×depositor π Customer_name (  account.account_number = depositor.account_number ( ) ) π Customer_name (  account.account_number = depositor.account_number  balance> ’ 700 ’ ( account ×depositor ) ) A1: A2:

40 DataBase System Haichang Gao, Software School, Xidian University 40 Example Queries  Find all customers who have at least two deposits. customer_ name account_ number HayesA-102 JohnsonA-101 JohnsonA-201 JonesA-217 LindsayA-222 SmithA-215 TurnerA-305 depositor D1.cnameD1.a#D2.cnameD2.a# HayesA-102HayesA-102 HayesA-102JohnsonA-101 HayesA-102JohnsonA-201 …… JohnsonA-101JohnsonA-201 …… JohnsonA-201JohnsonA-101 ……  D1(cname,a#) (depositor) ×  D2(cname,a#) ( depositor) π D1.cname (  D1.cname=D2.cname ∧ D1.a#<>D2.a# ( ) )

41 DataBase System Haichang Gao, Software School, Xidian University 41 Example Queries  Find the largest account balance. account_ number Branch_ name balance A-101Downtown500 A-215Mianus700 A-102Perryridge400 ………… account A.anoA.bnA.bB.anoB.bnB.b A-101Downtown500A-101Downtown500 A-101Downtown500A-215Mianus700 A-101Downtown500A-102Perryridge400 A-215Mianus700A-101Downtown500 A-215Mianus700A-215Mianus700 A-215Mianus700A-102Perryridge400 A-102Perryridge400A-101Downtown500 A-102Perryridge400A-215Mianus700 A-102Perryridge400A-102Perryridge400 ……….……………  A.b > B.b (A × B)? π A1.balance (  A1.balance < A2.balance (  A1 (account) ×  A2 (account) ) ) π balance (account) –  A.b < B.b (A × B)?

42 DataBase System Haichang Gao, Software School, Xidian University 42 Additional Operations  We define additional operations that do not add any power to the relational algebra, but that simplify common queries.  Set intersection( 集合交 )  Natural join( 自然连接 )  Division( 除法 )

43 DataBase System Haichang Gao, Software School, Xidian University 43 Additional Operations  Intersection Operation( 交操作 )  Notation: r  s  Assume:  r, s have the same degree  attributes of r and s are compatible  Defined as: r  s ={ t | t  r  t  s }  Note: r  s = r - (r - s) π customer_name (borrower )  π customer_name (depositor )  Find the names of all customers who have a loan and an account at bank.

44 DataBase System Haichang Gao, Software School, Xidian University 44 Additional Operations   -Join Operation(  - 连接 )   -Join is a general join which don ’ t need there are same attribute for both operators, and the join condition can be any compare operations. That is: R times S WHERE F R S = { | t r  R  t s  S  t r [A]  t s [B] } AθB AθB t r t s  Equi-join is another join. Its join condition is equal operator. R S = { | t r  R  t s  S  t r [A]= t s [B] } A=B A=B t r t s

45 DataBase System Haichang Gao, Software School, Xidian University 45 Additional Operations   -Join Operation(  - 连接 ) Relations r, s: R ABC a1a1 b1b1 5 a1a1 b2b2 6 a2a2 b3b3 8 a2a2 b4b4 12 S BE b1b1 3 b2b2 7 b3b3 10 b3b3 2 b5b5 2 R S B = B AR.BCS.BE a1a1 b1b1 5b1b1 3 a1a1 b2b2 6b2b2 7 a2a2 b3b3 8b3b3 10 a2a2 b3b3 8b3b3 2 R S C < E ES.BCR.BA 10b3b3 5b1b1 a1a1 7b2b2 5b1b1 a1a1 b3b3 8b3b3 a2a2 b3b3 6b2b2 a1a1 7b2b2 6b2b2 a1a1

46 DataBase System Haichang Gao, Software School, Xidian University 46 Additional Operations  Natural join Operation( 自然连接 )  Notation: r s  Let r and s be relations on schemas R and S respectively.The result is a relation on schema R  S which is obtained by considering 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 of the attributes in R  S, a tuple t is added to the result, where  t has the same value as t r on r  t has the same value as t s on s  Example: R = (A, B, C, D)S = (E, B, D)  Result schema = (A, B, C, D, E)  r s is defined as: π r.A, r.B, r.C, r.D, s.E (  r.B = s.B r.D = s.D (r × s))

47 DataBase System Haichang Gao, Software School, Xidian University 47 Additional Operations  Natural join Operation( 自然连接 ) Relations r, s: AB  1241212412 CD  aababaabab r ABCDE B 1312313123 D aaabbaaabb E  s r s  1  a   1  a   1  a   1  a   2  b 

48 DataBase System Haichang Gao, Software School, Xidian University 48 Example Queries Additional Operations simplify the relational algebra expressions !  balance> ’ 700 ’ (account) π account_number ( ) ×depositor π Customer_name (  account.account_number = depositor.account_number ( ) ) A1: π Customer_name (  account.account_number = depositor.account_number  balance> ’ 700 ’ ( account ×depositor ) ) A2:  Find the customers name who have at least one deposit of a balance greater than $700. account depositor A3: π Customer_name (  balance> ’ 700 ’ ( ) )

49 DataBase System Haichang Gao, Software School, Xidian University 49 Example Queries  (exercise)Find all customers who have at least two deposits in different branch. customer_ name account_ number HayesA-102 JohnsonA-101 JohnsonA-201 JonesA-217 LindsayA-222 SmithA-215 TurnerA-305 depositor account_ number branch_ name balance A-101Downtown500 A-215Mianus700 A-102Perryridge400 A-305Round Hill350 A-201Brighton900 A-222Redwood700 A-217Brighton750 account π D1.Customer_name (  D1.Customer_name =D2. Customer_name  D1. Account_number<>D2. Account_number  D1.branch_name<>D2. branch_name ( ) ×  D2 (depositor account)  D1 (depositor account)

50 DataBase System Haichang Gao, Software School, Xidian University 50 Example Queries  (exercise)Find all customers who have at least two deposits in different branch. customer_ name account_ number HayesA-102 JohnsonA-101 JohnsonA-201 JonesA-217 LindsayA-222 SmithA-215 TurnerA-305 depositor account_ number branch_ name balance A-101Downtown500 A-215Mianus700 A-102Perryridge400 A-305Round Hill350 A-201Brighton900 A-222Redwood700 A-217Brighton750 account  depositor.account_number=account.account_number (depositor × account))  D1(cname,a#,bname) (π depositor.customer_name,account_number,branch_name  D2(cname,a#,bname) (π depositor.customer_name,account_number,branch_name  depositor.account_number=account.account_number (depositor × account)) × π D1.cname (  D1.cname=D2.cname  D1.a#<>D2.a#  D1.bname<>D2.bname ( )

51 DataBase System Haichang Gao, Software School, Xidian University 51 Additional Operations  Division Operation( 除 )  Suited to queries that include the phrase “ for all ”.  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 ) The result of r  s is a relation on schema R  S = (A 1, …, A m )  Defined as: r  s = { t | t  π R-S (r)   u  s → tu  r ) }

52 DataBase System Haichang Gao, Software School, Xidian University 52 Additional Operations  Division Operation( 除 ) Relations r, s: r  s:r  s: B A 1212 AB  1231113461212311134612 r s  

53 DataBase System Haichang Gao, Software School, Xidian University 53 Additional Operations  Division Operation( 除 )  Another Defined as: Y x ={y | t r ∈ R  y=t r [Y]  x=t r [X]} AB  aaaaaaaaaaaaaaaa CD  aabababbaabababb E 1111311111113111 D abab E 1111 r s r  s:r  s: ABC Relations r, s:  a   a 

54 DataBase System Haichang Gao, Software School, Xidian University 54 Additional Operations  Division Operation( 除 )  Property  Let q is the result of r  s  Then q is the largest relation satisfying q × s  r  Definition in terms of the basic algebra operation Let r(R) and s(S) be relations, and let S  R r  s = π R-S (r) – π R-S ( (π R-S (r) × s) – π R-S,S (r))

55 DataBase System Haichang Gao, Software School, Xidian University 55 Example Queries  Find all customers who have an account at all branches located in Brooklyn city. branch_namebranch_cityassets BrightonBrooklyn7100000 DowntownBrooklyn9000000 MianusHorseneck400000 North TownRye3700000 PerryridgeHorseneck1700000 PownalBennington300000 RedwoodPaloAlto2100000 Round HillHorseneck8000000 branch π branch_name (  branch_city = “Brooklyn” (branch)) account_ number branch_ name balance A-101Downtown500 A-215Mianus700 A-102Perryridge400 A-305Round Hill350 A-201Brighton900 A-222Redwood700 A-217Brighton750 account customer_ name Johnson Smith Hayes Turner Johnson Lindsay Jones  π customer_name, branch_name (depositor account) 

56 DataBase System Haichang Gao, Software School, Xidian University 56 Extended Operations  Outer join Operation( 外连接 )  The (left) Outer join is a join on which tuples from R that do not have matching values in the common attributes of S are alse included in the result relation. Missing values in the second relation are set to null. AB  1212 s AC  10 20 10 D aabbaabb r ACDB  a 1  a 2  20b 2  10b r s  Notation: r s (left outer join )

57 DataBase System Haichang Gao, Software School, Xidian University 57 Extended Operations loan_numberbranch_nameamount L-170Downtown3000 L-230Redwood4000 L-260Perryridge1700 loan customer_nameloan_number JonesL-170 SmithL-230 HayesL-155 borrower loan_numberbranch_Nameamount customer_name L-170Downtown3000Jones L-230Redwood4000Smith  Inner Join: loan borrower  Left Outer Join : loan borrower loan_numberbranch_Nameamount customer_name L-170Downtown3000Jones L-230Redwood4000Smith L-260Perryridge1700NULL

58 DataBase System Haichang Gao, Software School, Xidian University 58 Extended Operations loan_numberbranch_nameamount L-170Downtown3000 L-230Redwood4000 L-260Perryridge1700 loan customer_nameLoan_number JonesL-170 SmithL-230 HayesL-155 borrower loan_numbernranch_nameamount customer_name L-170Downtown3000Jones L-230Redwood4000Smith L-155Hayes loan_numberbranch_nameamount customer_name L-170Downtown3000Jones L-230Redwood4000Smith L-260Perryridge1700 L-155Hayes  Right Outer Join : loan borrower  Full Outer Join : loan borrower

59 DataBase System Haichang Gao, Software School, Xidian University 59 Homework 1  2.1  2.5

60 DataBase System Haichang Gao, Software School, Xidian University 60 Homework 1 讲解  2.1a ∏ p1 (  e1.m1=e2.p2  e1.s1=e2.s2  e1.c1=e2.c2 (ρ e1(p1,s1,c1,m1) (employee manages) × ρ e2(p2,s2,c2) (employee))) (∏ e1.p1,e2.p2 (  e1.p1  e2.p2  e1.s1=e2.s2  e1.c1=e2.c2 (ρ e1(p1,s1,c1) (employee) × ρ e2(p2,s2,c2) (employee)))) ρ m1(p1,p2) ( managers)

61 DataBase System Haichang Gao, Software School, Xidian University 61 Homework 1  2.1b ∏ person_name (  company_name  “First Bank Corporation” (works)) ∏ person_name (employee)- ∏ person_name (  company_name = “First Bank Corporation” (works))

62 DataBase System Haichang Gao, Software School, Xidian University 62 Homework 1  2.1c ∏ person_name (employee)- ∏ w1.person_name (  w1.salary  w2.salary  w2.company_name = “Small Bank Corporation” (ρ w1 (works)×ρ w2 (works))

63 DataBase System Haichang Gao, Software School, Xidian University 63 Homework 1  2.5a ∏ person_name (  company_name = “First Bank Corporation” (works))  2.5b ∏ person_name, city (  company_name = “First Bank Corporation” (works employee))  2.5c ∏ person_name, street, city (  company_name = “First Bank Corporation”  salary>10000 (works employee))

64 DataBase System Haichang Gao, Software School, Xidian University 64 Homework 1  2.5d ∏ person_name  e.city=c.city ( (employee works company))  2.5e ∏ c1.company_name  c1.city=c2.city (ρ c1 (company)×ρ c2 ( ∏ city (  company_name= “Small Bank Corporation” (company)))) Assume the companies may be located in several cities. Find all companies located in every city in which Small Bank Corporation is located.


Download ppt "Database Systems. DataBase System Haichang Gao, Software School, Xidian University 2 Major Content & Grade  Introduction*  The Relational Model** "

Similar presentations


Ads by Google