数据库chapter2
- 格式:pdf
- 大小:300.32 KB
- 文档页数:28
数据库系统概念知识点整理冶旭华东师范大学10计算机科学技术系Chapter 1 引言数据库管理系统(DBMS):由一个互相关联的数据的集合和一组用以访问这些数据的程序组成,数据描述某特定的企业。
DBMS的主要目标是为人们提供方便高效的环境来存储和检索数据。
数据不一致性:即同一数据的不同副本不一致。
模式分为数据库模式,物理模式和逻辑模式。
物理数据独立性:应用程序如果不依赖于物理模式,它们就被称为是具有物理数据独立性,因此即使物理模式改变了它们也无须重写。
数据模型:是数据库结构的基础,是一个用于描述数据、数据联系、数据语义和数据约束的概念工具的集合。
数据操纵语言(DML):是使得用户可以访问和操纵数据的语言。
分为过程化和非过程DML (即声明式DML)。
过程化DML:要求用户指定需要什么数据以及如何获得这些数据。
非过程化DML:只要求用户指定需要什么数据,而不指明如何获得这些数据。
事务:是数据库应用中完成单一逻辑功能的操作集合,是一个既具有原子性又具有一致性的单元。
事务管理:负责保证不管是否有故障发生,数据库都要处于一致的(正确的)状态。
事务管理器还保证并发事务的执行互不冲突。
数据库管理员(DBA):对系统进行集中控制的人。
Chapter 2 关系模型关系数据模型(relational data model): 建立在表的集合的基础上。
数据库系统的用户可以对这些表进行查询,可以插入新元组、删除元组以及更新(修改)元组。
关系代数:定义了一套在表上运算,且输出结果也是表的代数运算。
这些运算可以混合使用以得到表达所希望查询的表达式。
关系代数定义了关系查询语言中使用的基本运算。
关系代数运算可分为:基本运算(选择,投影,并,集合差,笛卡尔积,更名);附加运算(集合交,自然连接,除,赋值),扩展的运算(广义投影,聚集函数,外连接)。
码:是整个关系的性质,而不是一个个元组的性质。
关系中的任意两个元组都不允许同时在码属性上具有相同的值。
数据仓库与数据挖掘教程(第2版)课后习题答案第二章1. 什么是数据仓库?它与传统数据库有什么不同?答:数据仓库是一个面向主题、集成、稳定、可学习的数据集合,用于支持企业决策制定和决策支持系统。
与传统数据库相比,数据仓库更注重数据的整合和大数据的处理能力,以支持更高级别的数据分析和决策。
2. 什么是元数据?有哪些类型?答:元数据指描述数据仓库中数据的数据,用于描述数据的含义、格式、内容、质量、来源、使用和存储等方面的信息。
元数据有三种类型:技术元数据、业务元数据和操作元数据。
3. 数据仓库的架构有哪些组成部分?请简述各组成部分的作用。
答:数据仓库的架构主要包括数据源、数据抽取、清理和转换、存储和管理、元数据管理、查询和分析等几个组成部分。
- 数据源:指数据仓库的数据来源,可以是事务处理系统、外部数据源、第三方提供商等。
- 数据抽取、清理和转换:将数据从各种不同的来源抽取出来并转化为简单、标准的格式,以便进行加工和分析。
- 存储和管理:将经过抽取、转换和清洗后的数据存储在数据仓库中并进行管理,查找、更新和删除等操作。
- 元数据管理:对数据仓库中的元数据进行管理,并将其存储在元数据存储库中。
- 查询和分析:通过各种查询和分析工具来进行数据挖掘、分析和报告。
4. 请列出数据仓库中的三种主要数据类型。
答:数据仓库中的三种主要数据类型包括事实数据、维度数据和元数据。
5. 请列出数据仓库的三种不同的操作类型。
答:数据仓库的三种不同的操作类型包括基础操作、加工操作和查询操作。
6. 数据挖掘的定义是什么?答:数据挖掘是一种通过分析大量数据来发现有意义模式、趋势和关联的过程。
它是既包含统计学、机器学习和数据库技术的交叉学科,又包含更广泛的知识和业务领域。
7. 请列出数据挖掘中的四个主要任务。
答:数据挖掘中的四个主要任务包括描述性数据挖掘、预测性数据挖掘、关联数据挖掘和分类和聚类。
8. 数据仓库中经常使用OLAP分析方式,您了解OLAP是什么吗?答: OLAP是一种面向主题的数据分析方式,可以帮助用户对快速变化的数据进行多维分析和决策支持。
Database Systems: The Complete BookSolutions for Chapter 2Solutions for Section 2.1Exercise 2.1.1The E/R Diagram.Exercise 2.1.8(a)The E/R DiagramKobvxybzSolutions for Section 2.2Exercise 2.2.1The Addresses entity set is nothing but a single address, so we would prefer to make address an attribute of Customers. Were the bank to record several addresses for a customer, then it might make sense to have an Addresses entity set and make Lives-at a many-many relationship.The Acct-Sets entity set is useless. Each customer has a unique account set containing his or her accounts. However, relating customers directly to their accounts in a many-many relationship conveys the same information and eliminates the account-set concept altogether.Solutions for Section 2.3Exercise 2.3.1(a)Keys ssNo and number are appropriate for Customers and Accounts, respectively. Also, we think it does not make sense for an account to be related to zero customers, so we should round the edge connecting Owns to Customers. It does not seem inappropriate to have a customer with 0 accounts;they might be a borrower, for example, so we put no constraint on the connection from Owns to Accounts. Here is the The E/R Diagram,showing underlined keys andthe numerocity constraint.Exercise 2.3.2(b)If R is many-one from E1 to E2, then two tuples (e1,e2) and (f1,f2) of the relationship set for R must be the same if they agree on the key attributes for E1. To see why, surely e1 and f1 are the same. Because R is many-one from E1 to E2, e2 and f2 must also be the same. Thus, the pairs are the same.Solutions for Section 2.4Exercise 2.4.1Here is the The E/R Diagram.We have omitted attributes other than our choice for the key attributes of Students and Courses. Also omitted are names for the relationships. Attribute grade is not part of the key for Enrollments. The key for Enrollements is studID from Students and dept and number from Courses.Exercise 2.4.4bHere is the The E/R Diagram Again, we have omitted relationship names and attributes other than our choice for the key attributes. The key for Leagues is its own name; this entity set is not weak. The key for Teams is its own name plus the name of the league of which the team is a part, e.g., (Rangers, MLB) or (Rangers, NHL). The key for Players consists of the player's number and the key for the team on which he or she plays. Since the latter key is itself a pair consisting of team and league names, the key for players is the triple (number, teamName, leagueName). e.g., JeffGarcia is (5, 49ers, NFL).Database Systems: The Complete BookSolutions for Chapter 3Solutions for Section 3.1Exercise 3.1.2(a)We can order the three tuples in any of 3! = 6 ways. Also, the columns can be ordered in any of 3! = 6 ways. Thus, the number of presentations is 6*6 = 36.Solutions for Section 3.2Exercise 3.2.1Customers(ssNo, name, address, phone)Flights(number, day, aircraft)Bookings(ssNo, number, day, row, seat)Being a weak entity set, Bookings' relation has the keys for Customers and Flights and Bookings' own attributes.Notice that the relations obtained from the toCust and toFlt relationships are unnecessary. They are:toCust(ssNo, ssNo1, number, day)toFlt(ssNo, number, day, number1, day1)That is, for toCust, the key of Customers is paired with the key for Bookings. Since both include ssNo, this attribute is repeated with two different names, ssNo and ssNo1. A similar situation exists for toFlt.Exercise 3.2.3Ships(name, yearLaunched)SisterOf(name, sisterName)Solutions for Section 3.3Exercise 3.3.1Since Courses is weak, its key is number and the name of its department. We do not have arelation for GivenBy. In part (a), there is a relation for Courses and a relation for LabCourses that has only the key and the computer-allocation attribute. It looks like:Depts(name, chair)Courses(number, deptName, room)LabCourses(number, deptName, allocation)For part (b), LabCourses gets all the attributes of Courses, as:Depts(name, chair)Courses(number, deptName, room)LabCourses(number, deptName, room, allocation)And for (c), Courses and LabCourses are combined, as:Depts(name, chair)Courses(number, deptName, room, allocation)Exercise 3.3.4(a)There is one relation for each entity set, so the number of relations is e. The relation for the root entity set has a attributes, while the other relations, which must include the key attributes, have a+k attributes.Solutions for Section 3.4Exercise 3.4.2Surely ID is a key by itself. However, we think that the attributes x, y, and z together form another key. The reason is that at no time can two molecules occupy the same point.Exercise 3.4.4The key attributes are indicated by capitalization in the schema below:Customers(SSNO, name, address, phone)Flights(NUMBER, DAY, aircraft)Bookings(SSNO, NUMBER, DAY, row, seat)Exercise 3.4.6(a)The superkeys are any subset that contains A1. Thus, there are 2^{n-1} such subsets, since each of the n-1 attributes A2 through An may independently be chosen in or out.Solutions for Section 3.5Exercise 3.5.1(a)We could try inference rules to deduce new dependencies until we are satisfied we have them all.A more systematic way is to consider the closures of all 15 nonempty sets of attributes.For the single attributes we have A+ = A, B+ = B, C+ = ACD, and D+ = AD. Thus, the only new dependency we get with a single attribute on the left is C->A.Now consider pairs of attributes:AB+ = ABCD, so we get new dependency AB->D. AC+ = ACD, and AC->D is nontrivial. AD+ = AD, so nothing new. BC+ = ABCD, so we get BC->A, and BC->D. BD+ = ABCD, giving usBD->A and BD->C. CD+ = ACD, giving CD->A.For the triples of attributes, ACD+ = ACD, but the closures of the other sets are each ABCD. Thus, we get new dependencies ABC->D, ABD->C, and BCD->A.Since ABCD+ = ABCD, we get no new dependencies.The collection of 11 new dependencies mentioned above is: C->A, AB->D, AC->D, BC->A, BC->D, BD->A, BD->C, CD->A, ABC->D, ABD->C, and BCD->A.Exercise 3.5.1(b)From the analysis of closures above, we find that AB, BC, and BD are keys. All other sets either do not have ABCD as the closure or contain one of these three sets.Exercise 3.5.1(c)The superkeys are all those that contain one of those three keys. That is, a superkey that is not a key must contain B and more than one of A, C, and D. Thus, the (proper) superkeys are ABC, ABD, BCD, and ABCD.Exercise 3.5.3(a)We must compute the closure of A1A2...AnC. Since A1A2...An->B is a dependency, surely B is in this set, proving A1A2...AnC->B.Exercise 3.5.4(a)Consider the relationThis relation satisfies A->B but does not satisfy B->A.Exercise 3.5.8(a)If all sets of attributes are closed, then there cannot be any nontrivial functional dependenc ies. For suppose A1A2...An->B is a nontrivial dependency. Then A1A2...An+ contains B and thus A1A2...An is not closed.Exercise 3.5.10(a)We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets: A+ = AB+ = BC+ = ACEAB+ = ABCDEAC+ = ACEBC+ = ABCDEWe ignore D and E, so a basis for the resulting functional dependencies for ABC are: C->A and AB->C. Note that BC->A is true, but follows logically from C->A, and therefore may be omitted from our list.Solutions for Section 3.6Exercise 3.6.1(a)In the solution to Exercise 3.5.1 we found that there are 14 nontrivial dependencies, including the three given ones and 11 derived dependencies. These are: C->A, C->D, D->A, AB->D, AB-> C, AC->D, BC->A, BC->D, BD->A, BD->C, CD->A, ABC->D, ABD->C, and BCD->A.We also learned that the three keys were AB, BC, and BD. Thus, any dependency above that does not have one of these pairs on the left is a BCNF violation. These are: C->A, C->D, D->A, AC->D, and CD->A.One choice is to decompose using C->D. That gives us ABC and CD as decomposed relations. CD is surely in BCNF, since any two-attribute relation is. ABC is not in BCNF, since AB and BC are its only keys, but C->A is a dependency that holds in ABCD and therefore holds in ABC. We must further decompose ABC into AC and BC. Thus, the three relations of the decomposition are AC, BC, and CD.Since all attributes are in at least one key of ABCD, that relation is already in 3NF, and no decomposition is necessary.Exercise 3.6.1(b)(Revised 1/19/02) The only key is AB. Thus, B->C and B->D are both BCNF violations. The derived FD's BD->C and BC->D are also BCNF violations. However, any other nontrivial, derived FD will have A and B on the left, and therefore will contain a key.One possible BCNF decomposition is AB and BCD. It is obtained starting with any of the four violations mentioned above. AB is the only key for AB, and B is the only key for BCD.Since there is only one key for ABCD, the 3NF violations are the same, and so is the decomposition.Solutions for Section 3.7Exercise 3.7.1Since A->->B, and all the tuples have the same value for attribute A, we can pair the B-value from any tuple with the value of the remaining attribute C from any other tuple. Thus, we know that R must have at least the nine tuples of the form (a,b,c), where b is any of b1, b2, or b3, and c is any of c1, c2, or c3. That is, we can derive, using the definition of a multivalued dependency, that each of the tuples (a,b1,c2), (a,b1,c3), (a,b2,c1), (a,b2,c3), (a,b3,c1), and (a,b3,c2) are also in R.Exercise 3.7.2(a)First, people have unique Social Security numbers and unique birthdates. Thus, we expect the functional dependencies ssNo->name and ssNo->birthdate hold. The same applies to children, so we expect childSSNo->childname and childSSNo->childBirthdate. Finally, an automobile has a unique brand, so we expect autoSerialNo->autoMake.There are two multivalued dependencies that do not follow from these functional dependencies. First, the information about one child of a person is independent of other information about that person. That is, if a person with social security number s has a tuple with cn,cs,cb, then if there isany other tuple t for the same person, there will also be another tuple that agrees with t except that it has cn,cs,cb in its components for the child name, Social Security number, and birthdate. That is the multivalued dependencyssNo->->childSSNo childName childBirthdateSimilarly, an automobile serial number and make are independent of any of the other attributes, so we expect the multivalued dependencyssNo->->autoSerialNo autoMakeThe dependencies are summarized below:ssNo -> name birthdatechildSSNo -> childName childBirthdateautoSerialNo -> autoMakessNo ->-> childSSNo childName childBirthdatessNo ->-> autoSerialNo autoMakeExercise 3.7.2(b)We suggest the relation schemas{ssNo, name, birthdate}{ssNo, childSSNo}{childSSNo, childName childBirthdate}{ssNo, autoSerialNo}{autoSerialNo, autoMake}An initial decomposition based on the two multivalued dependencies would give us {ssNo, name, birthDate}{ssNo, childSSNo, childName, childBirthdate}{ssNo, autoSerialNo, autoMake}Functional dependencies force us to decompose the second and third of these.Exercise 3.7.3(a)Since there are no functional dependencies, the only key is all four attributes, ABCD. Thus, each of the nontrvial multivalued dependencies A->->B and A->->C violate 4NF. We must separate out the attributes of these dependencies, first decomposing into AB and ACD, and then decomposing the latter into AC and AD because A->->C is still a 4NF violation for ACD. The final set of relations are AB, AC, and AD.Exercise 3.7.7(a)Let W be the set of attributes not in X, Y, or Z. Consider two tuples xyzw and xy'z'w' in the relation R in question. Because X ->-> Y, we can swap the y's, so xy'zw and xyz'w' are in R. Because X ->-> Z, we can take the pair of tuples xyzw and xyz'w' and swap Z's to get xyz'w and xyzw'. Similarly, we can take the pair xy'z'w' and xy'zw and swap Z's to get xy'zw' and xy'z'w.In conclusion, we started with tuples xyzw and xy'z'w' and showed that xyzw' and xy'z'w must also be in the relation. That is exactly the statement of the MVD X ->-> Y-union-Z. Note that the above statements all make sense even if there are attributes in common among X, Y, and Z.Exercise 3.7.8(a)Consider a relation R with schema ABCD and the instance with four tuples abcd, abcd', ab'c'd, and ab'c'd'. This instance satisfies the MVD A->-> BC. However, it does not satisfy A->-> B. For example, if it did satisfy A->-> B, then because the instance contains the tuples abcd and ab'c'd, we would expect it to contain abc'd and ab'cd, neither of which is in the instance.Database Systems: The Complete BookSolutions for Chapter 4Solutions for Section 4.2Exercise 4.2.1class Customer {attribute string name;attribute string addr;attribute string phone;attribute integer ssNo;relationship Set<Account> ownsAcctsinverse Account::ownedBy;}class Account {attribute integer number;attribute string type;attribute real balance;relationship Set<Customer> ownedByinverse Customer::ownsAccts}Exercise 4.2.4class Person {attribute string name;relationship Person motherOfinverse Person::childrenOfFemalerelationship Person fatherOfinverse Person::childrenOfMalerelationship Set<Person> childreninverse Person::parentsOfrelationship Set<Person> childrenOfFemaleinverse Person::motherOfrelationship Set<Person> childrenOfMaleinverse Person::fatherOfrelationship Set<Person> parentsOfinverse Person::children}Notice that there are six different relationships here. For example, the inverse of the relationship that connects a person to their (unique) mother is a relationship that connects a mother (i.e., a female person) to the set of her children. That relationship, which we call childrenOfFemale, is different from the children relationship, which connects anyone -- male or female -- to their children.Exercise 4.2.7A relationship R is its own inverse if and only if for every pair (a,b) in R, the pair (b,a) is also in R. In the terminology of set theory, the relation R is ``symmetric.''Solutions for Section 4.3Exercise 4.3.1We think that Social Security number should me the key for Customer, and account number should be the key for Account. Here is the ODL solution with key and extent declarations.class Customer(extent Customers key ssNo){attribute string name;attribute string addr;attribute string phone;attribute integer ssNo;relationship Set<Account> ownsAcctsinverse Account::ownedBy;}class Account(extent Accounts key number){attribute integer number;attribute string type;attribute real balance;relationship Set<Customer> ownedByinverse Customer::ownsAccts}Solutions for Section 4.4Exercise 4.4.1(a)Since the relationship between customers and accounts is many-many, we should create a separate relation from that relationship-pair.Customers(ssNo, name, address, phone)Accounts(number, type, balance)CustAcct(ssNo, number)Exercise 4.4.1(d)Ther is only one attribute, but three pairs of relationships from Person to itself. Since motherOf and fatherOf are many-one, we can store their inverses in the relation for Person. That is, for each person, childrenOfMale and childrenOfFemale will indicate that persons's father and mother. The children relationship is many-many, and requires its own relation. This relation actually turns out to be redundant, in the sense that its tuples can be deduced from the relationships stored with Person. The schema:Persons(name, childrenOfFemale, childrenOfMale)Parent-Child(parent, child)Exercise 4.4.4Y ou get a schema like:Studios(name, address, ownedMovie)Since name -> address is the only FD, the key is {name, ownedMovie}, and the FD has a left side that is not a superkey.Exercise 4.4.5(a,b,c)(a) Struct Card { string rank, string suit };(b) class Hand {attribute Set theHand;};For part (c) we have:Hands(handId, rank, suit)Notice that the class Hand has no key, so we need to create one: handID. Each hand has, in the relation Hands, one tuple for each card in the hand.Exercise 4.4.5(e)Struct PlayerHand { string Player, Hand theHand };class Deal {attribute Set theDeal;}Alternatively, PlayerHand can be defined directly within the declaration of attribute theDeal. Exercise 4.4.5(h)Since keys for Hand and Deal are lacking, a mechanical way to design the database schema is to have one relation connecting deals and player-hand pairs, and another to specify the contents of hands. That is:Deals(dealID, player, handID)Hands(handID, rank, suit)However, if we think about it, we can get rid of handID and connect the deal and the player directly to the player's cards, as:Deals(dealID, player, rank, suit)Exercise 4.4.5(i)First, card is really a pair consisting of a suit and a rank, so we need two attributes in a relation schema to represent cards. However, much more important is the fact that the proposed schema does not distinguish which card is in which hand. Thus, we need another attribute that indicates which hand within the deal a card belongs to, something like:Deals(dealID, handID, rank, suit)Exercise 4.4.6(c)Attribute b is really a bag of (f,g) pairs. Thus, associated with each a-value will be zero or more (f,g) pairs, each of which can occur several times. We shall use an attribute count to indicate the number of occurrences, although if relations allow duplicate tuples we could simply allow duplicate (a,f,g) triples in the relation. The proposed schema is:C(a, f, g, count)Solutions for Section 4.5Exercise 4.5.1(b)Studios(name, address, movies{(title, year, inColor, length,stars{(name, address, birthdate)})})Since the information about a star is repeated once for each of their movies, there is redundancy. To eliminate it, we have to use a separate relation for stars and use pointers from studios. That is: Stars(name, address, birthdate)Studios(name, address, movies{(title, year, inColor, length,stars{*Stars})})Since each movie is owned by one studio, the information about a movie appears in only one tuple of Studios, and there is no redundancy.Exercise 4.5.2Customers(name, address, phone, ssNo, accts{*Accounts})Accounts(number, type, balance, owners{*Customers})Solutions for Section 4.6Exercise 4.6.1(a)We need to add new nodes labeled George Lucas and Gary Kurtz. Then, from the node sw (which represents the movie Star Wars), we add arcs to these two new nodes, labeled direc tedBy and producedBy, respectively.Exercise 4.6.2Create nodes for each account and each customer. From each customer node is an arc to a node representing the attributes of the customer, e.g., an arc labeled name to the customer's name. Likewise, there is an arc from each account node to each attribute of that account, e.g., an arc labeled balance to the value of the balance.To represent ownership of accounts by customers, we place an arc labeled owns from each customer node to the node of each account that customer holds (possibly jointly). Also, we placean arc labeled ownedBy from each account node to the customer node for each owner of that account.Exercise 4.6.5In the semistructured model, nodes represent data elements, i.e., entities rather than entity sets. In the E/R model, nodes of all types represent schema elements, and the data is not represented at all. Solutions for Section 4.7Exercise 4.7.1(a)<STARS-MOVIES><STAR starId = "cf" starredIn = "sw, esb, rj"><NAME>Carrie Fisher</NAME><ADDRESS><STREET>123 Maple St.</STREET><CITY>Hollywood</CITY></ADDRESS><ADDRESS><STREET>5 Locust Ln.</STREET><CITY>Malibu</CITY></ADDRESS></STAR><STAR starId = "mh" starredIn = "sw, esb, rj"><NAME>Mark Hamill</NAME><ADDRESS><STREET>456 Oak Rd.<STREET><CITY>Brentwood</CITY></ADDRESS></STAR><STAR starId = "hf" starredIn = "sw, esb, rj, wit"><NAME>Harrison Ford</NAME><ADDRESS><STREET>whatever</STREET><CITY>whatever</CITY></ADDRESS></STAR><MOVIE movieId = "sw" starsOf = "cf, mh"><TITLE>Star Wars</TITLE><YEAR>1977</YEAR></MOVIE><MOVIE movieId = "esb" starsOf = "cf, mh"><TITLE>Empire Strikes Back</TITLE><YEAR>1980</YEAR></MOVIE><MOVIE movieId = "rj" starsOf = "cf, mh"><TITLE>Return of the Jedi</TITLE><YEAR>1983</YEAR></MOVIE><MOVIE movieID = "wit" starsOf = "hf"><TITLE>Witness</TITLE><YEAR>1985</YEAR></MOVIE></STARS-MOVIES>Exercise 4.7.2<!DOCTYPE Bank [<!ELEMENT BANK (CUSTOMER* ACCOUNT*)><!ELEMENT CUSTOMER (NAME, ADDRESS, PHONE, SSNO)> <!A TTLIST CUSTOMERcustId IDowns IDREFS><!ELEMENT NAME (#PCDA TA)><!ELEMENT ADDRESS (#PCDA TA)><!ELEMENT PHONE (#PCDA TA)><!ELEMENT SSNO (#PCDA TA)><!ELEMENT ACCOUNT (NUMBER, TYPE, BALANCE)><!A TTLIST ACCOUNTacctId IDownedBy IDREFS><!ELEMENT NUMBER (#PCDA TA)><!ELEMENT TYPE (#PCDA TA)><!ELEMENT BALANCE (#PCDA TA)>]>Database Systems: The CompleteBookSolutions for Chapter 5Solutions for Section 5.2Exercise 5.2.1(a)PI_model( SIGMA_{speed >= 1000} ) (PC)Exercise 5.2.1(f)The trick is to theta-join PC with itself on the condition that the hard disk sizes are equal. That gives us tuples that have two PC model numbers with the same value of hd. However, these two PC's could in fact be the same, so we must also require in the theta-join that the model numbers be unequal. Finally, we want the hard disk sizes, so we project onto hd.The expression is easiest to see if we write it using some temporary values. We start by renaming PC twice so we can talk about two occurrences of the same attributes.R1 = RHO_{PC1} (PC)R2 = RHO_{PC2} (PC)R3 = R1 JOIN_{PC1.hd = PC2.hd AND PC1.model <> PC2.model} R2R4 = PI_{PC1.hd} (R3)Exercise 5.2.1(h)First, we find R1, the model-speed pairs from both PC and Laptop. Then, we find from R1 those computers that are ``fast,'' at least 133Mh. At the same time, we join R1 with Product to connect model numbers to their manufacturers and we project out the speed to get R2. Then we join R2 with itself (after renaming) to find pairs of different models by the same maker. Finally, we get our answer, R5, by projecting onto one of the maker attributes. A sequence of steps giving the desired expression is: R1 = PI_{model,speed} (PC) UNION PI_{model,speed} (Laptop)R2 = PI_{maker,model} (SIGMA_{speed>=700} (R1) JOIN Product)R3 = RHO_{T(maker2, model2)} (R2)R4 = R2 JOIN_{maker = maker2 AND model <> model2} (R3)R5 = PI_{maker} (R4)Exercise 5.2.2Here are figures for the expression trees of Exercise 5.2.1 Part (a)Part (f)Part (h). Note that the third figure is not really a tree, since it uses a common subexpression. We could duplicate the nodes to make it a tree, but using common subexpressions is a valuable form of query optimization. One of the benefits one gets from constructing ``trees'' for queries is the ability to combine nodes that represent common subexpressions.Exercise 5.2.7The relation that results from the natural join has only one attribute from each pair of equated attributes. The theta-join has attributes for both, and their columns are identical.Exercise 5.2.9(a)If all the tuples of R and S are different, then the union has n+m tuples, and this number is the maximum possible.The minimum number of tuples that can appear in the result occurs if every tuple of one relation also appears in the other. Surely the union has at least as many tuples as the larger of R and that is, max(n,m) tuples. However, it is possible for every tuple of the smaller to appear in the other, so it is possible that there are as few as max(n,m) tuples in the union.Exercise 5.2.10In the following we use the name of a relation both as its instance (set of tuples) and as its schema (set of attributes). The context determines uniquely which is meant.PI_R(R JOIN S) Note, however, that this expression works only for sets; it does not preserve the multipicity of tuples in R. The next two expressions work for bags.R JOIN DELTA(PI_{R INTERSECT S}(S)) In this expression, each projection of a tuple from S onto the attributes that are also in R appears exactly once in the second argument of the join, so it preserves multiplicity of tuples in R, except for those thatdo not join with S, which disappear. The DELTA operator removes duplicates, as described in Section 5.4.R - [R - PI_R(R JOIN S)] Here, the strategy is to find the dangling tuples of R and remove them.Solutions for Section 5.3Exercise 5.3.1As a bag, the value is {700, 1500, 866, 866, 1000, 1300, 1400, 700, 1200, 750, 1100, 350, 733}. The order is unimportant, of course. The average is 959.As a set, the value is {700, 1500, 866, 1000, 1300, 1400, 1200, 750, 1100, 350, 733}, and the average is 967. H3>Exercise 5.3.4(a)As sets, an element x is in the left-side expression(R UNION S) UNION Tif and only if it is in at least one of R, S, and T. Likewise, it is in the right-side expressionR UNION (S UNION T)under exactly the same conditions. Thus, the two expressions have exactly the same members, and the sets are equal.As bags, an element x is in the left-side expression as many times as the sum of the number of times it is in R, S, and T. The same holds for the right side. Thus, as bags the expressions also have the same value.Exercise 5.3.4(h)As sets, element x is in the left sideR UNION (S INTERSECT T)if and only if x is either in R or in both S and T. Element x is in the right side(R UNION S) INTERSECT (R UNION T)if and only if it is in both R UNION S and R UNION T. If x is in R, then it is in both unions. If x is in both S and T, then it is in both union. However, if x is neither in R nor in both of S and T, then it cannot be in both unions. For example, suppose x is not in R and not in S. Then x is not in R UNION S. Thus, the statement of when x is in the right side is exactly the same as when it is in the left side: x is either in R or in both of S and T.Now, consider the expression for bags. Element x is in the left side the sum of the number of times it is in R plus the smaller of the number of times x is in S and the number of times x is in T. Likewise, the number of times x is in the right side is the smaller ofThe sum of the number of times x is in R and in S.The sum of the number of times x is in R and in T.A moment's reflection tells us that this minimum is the sum of the number of times x is in R plus the smaller of the number of times x is in S and in T, exactly as for the left side.Exercise 5.3.5(a)For sets, we observe that element x is in the left side(R INTERSECT S) - T。
第二章TD-SCDMA 网络结构2.1TD-SCDMA 网络结构(3GPP R4) (4)2.1.1PS域与CS域的公共实体 (6)2.1.1.1 HLR (本地位置寄存器) (6)2.1.1.2 VLR (访问位置寄存器) (7)2.1.1.3 AuC(鉴权中心) (8)2.1.1.4 EIR(设备识别寄存器) (9)2.1.2CS域实体 (10)2.1.2.1 MSC Server (MSC服务器) (10)2.1.2.2 CS-MGW(电路交换-媒体网关) (10)2.1.2.3 GMSC 服务器 (10)2.1.3PS域实体 (11)2.1.3.1 SGSN(服务GPRS支持节点) (11)2.1.3.2 GGSN(网关GPRS支持节点) (11)2.1.3.3 BG(边界网关) (11)2.1.4R4核心网外部接口名称与含义 (12)2.23GPP R5版本介绍 (13)2.3UTRAN接入网结构 (14)2.3.1通用协议结构 (15)2.3.2Iu接口信令协议(3GPP R5 25410-530) (19)2.3.3Iub接口信令协议(3GPP R5 25430-520) (24)2.3.4Iur接口信令协议(3GPP R5 25420-510) (28)2.3.5Iupc接口信令协议(3GPP R5 25450-510) (29)2.4本章练习 (30)本章目标:∙了解TD-SCDMA 系统R4网络结构∙了解TD-SCDMA 系统RAN中包括哪些网元∙至少说出3个Iub接口的功能∙了解Iu-CS接口协议栈结构∙了解Iu-PS接口协议栈结构∙了解Iur接口协议栈结构∙了解Iub接口协议栈结构2.1 TD-SCDMA 网络结构(3GPP R4)TD-SCDMA网络主要包括核心网和无线接入网两部分,核心网主要处理UMTS内部所有的语音呼叫,数据连接和交换,以及与外部其他网络的连接和路由选择。
实验二SQL Server 2000 查询分析器的使用1.建立数据库文件2.在数据库文件中建立表、修改表(主码、完整性约束的使用)3.查询操作(2)实验数据及具体要求1.对于教学数据库的三个基本表学生关系Student(SNO,SNAME,SSEX,SAGE,SDEPT)学习关系SC(SNO,CNO,GRADE)创建数据库文件create database jxgl创建学生关系Student(SNO,SNAME,SSEX,SAGE,SDEPT)use jxglCREATE TABLE Student(Sno CHAR(5) PRIMARY KEY,Sname CHAR(20) ,Ssex CHAR(2) check (ssex='男' or ssex='女'),Sage INT check(sage between 15 and 35),Sdept CHAR(15) check (sdept in ('CS','IS','MA','PH')));在student表中插入记录insert into studentvalues('95001','李勇','男',20,'CS')创建学习关系SC(SNO,CNO,GRADE)CREATE TABLE SC(Sno CHAR(9),Cno CHAR(4),Grade SMALLINT check(Grade between 0 and 100),PRIMARY KEY (Sno,Cno),/* 主码由两个属性构成,必须作为表级完整性进行定义*/ FOREIGN KEY (Sno) REFERENCES Student(Sno),/* 表级完整性约束条件,Sno是外码,被参照表是Student */ FOREIGN KEY (Cno) REFERENCES Course(Cno)/* 表级完整性约束条件, Cno是外码,被参照表是Course*/ );试用 SQL 的查询语句表达下列查询:1.使用查询分析器建立三个表并输入数据;2.查询选修了课程的学生人数;Select count(distinct sno) from sc /* 加distinct 去掉重复值后计数 */3.给CS系的学生开设5号课程,建立选课信息(成绩暂空)INSERT INTO scSELECT student.sno, o, NULL AS Expr1FROM student CROSS JOINcourseWHERE (student.sdept = 'CS') AND (o = '5')4.将95001学生选修3号课程的成绩改为该课的平均成绩UPDATE scSET grade =(SELECT AVG(grade)FROM scWHERE cno = '3')WHERE (sno = '95001')5.查询计算机系(CS)选修了两门及以上课程的学生的学号,姓名Select sno,snameFrom studentWhere sdept='CS' and sno in (select snofrom scwhere student.sno=sc.snoGroup by sc.sno having count(*)>=2)6.查询student表与sc表基于学号sno的等值连接/自然连接select *from student,scwhere student.sno=sc.sno或SELECT *FROM student INNER JOINsc ON student.sno = sc.sno7.查询课程之先修课的先修课(自身连接)SELECT o, second.cpnoFROM course first INNER JOINcourse second ON first.cpno = o8.查询学生及其选修课程、成绩等情况(不管是否选修均需列出学生信息)select student.sno,sname,ssex,sage,sdept,cno,gradefrom student,scwhere student.sno *=sc.sno或SELECT student.sno, student.sname, student.ssex, student.sage, student.sdept, o,sc.gradeFROM student LEFT OUTER JOINsc ON student.sno = sc.sno9.查询性别为男、课程成绩及格的学生信息及课程号、成绩select student.*,cno,gradefrom student,scwhere ssex='男' and student.sno=sc.sno and grade>=60SELECT student.*, o AS Expr1, sc.grade AS Expr2FROM student INNER JOINsc ON student.sno = sc.snoWHERE (student.ssex = '男') AND (sc.grade >= 60)10.查询与’张立’在同一个系学习的学生信息SELECT *FROM studentWHERE (sdept IN(SELECT sdeptFROM studentWHERE sname = '张立')) AND (sname <> '张立')或SELECT s1.*FROM student s1 , student s2WHERE (s2.sname = '张立') AND (s1.sname <> '张立') and (s1.sdept = s2.sdept)或SELECT s1.*FROM student s1 INNER JOINstudent s2 ON s1.sdept = s2.sdeptWHERE (s2.sname = '张立') AND (s1.sname <> '张立')11.查询选修了课程名为“数据库”的学生学号、姓名和所在系SELECT sno, sname, sdeptFROM studentWHERE (sno IN(SELECT snoFROM scWHERE cno IN(SELECT cnoFROM courseWHERE cname = '数据库')))或SELECT student.sno, student.sname, student.sdeptFROM student,sc,courseWHERE (ame = '数据库') and ( student.sno = sc.sno ) and (o = o)或SELECT student.sno, student.sname, student.sdeptFROM student INNER JOINsc ON student.sno = sc.sno INNER JOINcourse ON o = oWHERE (ame = '数据库')12.查询哪些课程只有女生选修SELECT DISTINCT cnameFROM courseWHERE ('女' = ALL(SELECT ssexFROM sc, studentWHERE (sc.sno = student.sno AND o = o)))或SELECT DISTINCT cnameFROM courseWHERE (NOT EXISTS(SELECT *FROM sc, studentWHERE (sc.sno = student.sno AND o = o AND student.ssex = '男')))13.查询所有未选修1号课程的学生姓名SELECT snameFROM studentWHERE (NOT EXISTS(SELECT *FROM SCWHERE Sno = Student.Sno AND Cno = '1'))14.查询平均成绩大于85分的学号、姓名、平均成绩SELECT student.sno, student.sname, AVG(sc.grade) AS Expr1FROM student,scwhere (student.sno = sc.sno)GROUP BY student.sno, student.snameHAVING (AVG(sc.grade) > 85)或SELECT student.sno, student.sname, AVG(sc.grade) AS Expr1FROM student INNER JOINsc ON student.sno = sc.snoGROUP BY student.sno, student.snameHAVING (AVG(sc.grade) > 85)。
For relation Accounts, the attributes are:acctNo, type, balanceFor relation Customers, the attributes are:firstName, lastName, idNo, accountExercise 2.2.1bFor relation Accounts, the tuples are:(12345, savings, 12000),(23456, checking, 1000),(34567, savings, 25)For relation Customers, the tuples are:(Robbie, Banks, 901-222, 12345),(Lena, Hand, 805-333, 12345),(Lena, Hand, 805-333, 23456)Exercise 2.2.1cFor relation Accounts and the first tuple, the components are:123456 → acctNosavings → type12000 → balanceFor relation Customers and the first tuple, the components are:Robbie → firstNameBanks → lastName901-222 → idNo12345 → accountExercise 2.2.1dFor relation Accounts, a relation schema is:Accounts(acctNo, type, balance)For relation Customers, a relation schema is:Customers(firstName, lastName, idNo, account) Exercise 2.2.1eAn example database schema is:Accounts (acctNo,type,balance)Customers (firstName,lastName,idNo,account)A suitable domain for each attribute:acctNo → Integertype → Stringbalance → IntegerfirstName → StringlastName → StringidNo → String (because there is a hyphen we cannot use Integer)account → IntegerExercise 2.2.1gAnother equivalent way to present the Account relation:Another equivalent way to present the Customers relation:Exercise 2.2.2Examples of attributes that are created for primarily serving as keys in a relation:Universal Product Code (UPC) used widely in United States and Canada to track products in stores.Serial Numbers on a wide variety of products to allow the manufacturer to individually track each product.Vehicle Identification Numbers (VIN), a unique serial number used by the automotive industry to identify vehicles.Exercise 2.2.3aWe can order the three tuples in any of 3! = 6 ways. Also, the columns can be ordered in any of 3! = 6 ways. Thus, the number of presentations is 6*6 = 36.Exercise 2.2.3bWe can order the three tuples in any of 5! = 120 ways. Also, the columns can be ordered in any of 4! = 24 ways. Thus, the number of presentations is 120*24 = 2880Exercise 2.2.3cWe can order the three tuples in any of m! ways. Also, the columns can be ordered in any of n! ways. Thus, the number of presentations is n!m!Exercise 2.3.1aCREATE TABLE Product (maker CHAR(30),model CHAR(10) PRIMARY KEY,type CHAR(15));CREATE TABLE PC (model CHAR(30),speed DECIMAL(4,2),ram INTEGER,hd INTEGER,price DECIMAL(7,2));Exercise 2.3.1cCREATE TABLE Laptop (model CHAR(30),speed DECIMAL(4,2),ram INTEGER,hd INTEGER,screen DECIMAL(3,1),price DECIMAL(7,2));Exercise 2.3.1dCREATE TABLE Printer (model CHAR(30),color BOOLEAN,type CHAR (10),price DECIMAL(7,2));Exercise 2.3.1eALTER TABLE Printer DROP color;Exercise 2.3.1fALTER TABLE Laptop ADD od CHAR (10) DEFAULT ‘none’; Exercise 2.3.2aCREATE TABLE Classes (class CHAR(20),type CHAR(5),country CHAR(20),numGuns INTEGER,bore DECIMAL(3,1),displacement INTEGER);Exercise 2.3.2bCREATE TABLE Ships (name CHAR(30),class CHAR(20),launched INTEGER);Exercise 2.3.2cCREATE TABLE Battles (name CHAR(30),date DATE);Exercise 2.3.2dCREATE TABLE Outcomes (ship CHAR(30),battle CHAR(30),result CHAR(10));Exercise 2.3.2eALTER TABLE Classes DROP bore;Exercise 2.3.2fALTER TABLE Ships ADD yard CHAR(30); Exercise 2.4.1aR1 := σspeed ≥ 3.00 (PC)R2 := πmodel(R1)model100510061013Exercise 2.4.1bR1 := σhd ≥ 100 (Laptop)R2 := Product (R1)R3 := πmaker (R2)makerEABFGExercise 2.4.1cR1 := σmaker=B (Product PC)R2 := σmaker=B (Product Laptop)R3 := σmaker=B (Product Printer)R4 := πmodel,price (R1)R5 := πmodel,price (R2)R6: = πmodel,price (R3)R7 := R4 R5 R6model price1004 6491005 6301006 10492007 1429Exercise 2.4.1dR1 := σcolor = true AND type = laser (Printer)R2 := πmodel (R1)model30033007Exercise 2.4.1eR1 := σtype=laptop (Product)R2 := σtype=PC(Product)R3 := πmaker(R1)R4 := πmaker(R2)R5 := R3 – R4Exercise 2.4.1fR1 := ρPC1(PC)R2 := ρPC2(PC)R3 := R1 (PC1.hd = PC2.hd AND PC1.model <> PC2.model) R2R4 := πhd(R3)Exercise 2.4.1gR1 := ρPC1(PC)R2 := ρPC2(PC)R3 := R1 (PC1.speed = PC2.speed AND PC1.ram = PC2.ram AND PC1.model < PC2.model) R2R4 := πPC1.model,PC2.model(R3)Exercise 2.4.1hR1 := πmodel(σspeed ≥ 2.80(PC)) πmodel(σspeed ≥ 2.80(Laptop))R2 := πmaker,model(R1 Product)R3 := ρR3(maker2,model2)(R2)R4 := R2 (maker = maker2 AND model <> model2) R3R5 := πmaker(R4)Exercise 2.4.1iR1 := πmodel,speed(PC)R2 := πmodel,speed(Laptop)R3 := R1 R2R4 := ρR4(model2,speed2)(R3)R5 := πmodel,speed (R3 (speed < speed2 ) R4)R6 := R3 – R5makerBExercise 2.4.1jR1 := πmaker,speed(Product PC)R2 := ρR2(maker2,speed2)(R1)R3 := ρR3(maker3,speed3)(R1)R4 := R1 (maker = maker2 AND speed <> speed2) R2R5 := R4 (maker3 = maker AND speed3 <> speed2 AND speed3 <> speed) R3R6 := πmaker(R5)makerFGhd25080160PC1.model PC2.model1004 1012makerBEmakerADEExercise 2.4.1kR1 := πmaker,model(Product PC)R2 := ρR2(maker2,model2)(R1)R3 := ρR3(maker3,model3)(R1)R4 := ρR4(maker4,model4)(R1)R5 := R1 (maker = maker2 AND model <> model2) R2R6 := R3 (maker3 = maker AND model3 <> model2 AND model3 <> model) R5R7 := R4 (maker4 = maker AND (model4=model OR model4=model2 OR model4=model3)) R6R8 := πmaker(R7)makerABDEExercise 2.4.2aπmodelσspeed≥3.00PCExercise 2.4.2bπmakerσhd ≥ 100 ProductLaptopExercise 2.4.2cσmaker=B πmodel,priceσmaker=B πmodel,price σmaker=Bπmodel,priceProduct PC Laptop Printer ProductProductExercise 2.4.2dPrinter σcolor = true AND type = laserπmodelExercise 2.4.2e σtype=laptop σtype=PC πmakerπmaker –Product ProductExercise 2.4.2fρPC1ρPC2 (PC1.hd = PC2.hd AND PC1.model <> PC2.model)πhdPC PCExercise 2.4.2gρPC1ρPC2PC PC(PC1.speed = PC2.speed AND PC1.ram = PC2.ram AND PC1.model < PC2.model)πPC1.model,PC2.modelExercise 2.4.2hPC Laptop σspeed ≥ 2.80σspeed ≥ 2.80πmodelπmodel πmaker,modelρR3(maker2,model2)(maker = maker2 AND model <> model2)makerExercise 2.4.2iPCLaptopProductπmodel,speed πmodel,speed ρR4(model2,speed2)πmodel,speed(speed < speed2 )–makerExercise 2.4.2jProduct PC πmaker,speed ρR3(maker3,speed3)ρR2(maker2,speed2)(maker = maker2 AND speed <> speed2)(maker3 = maker AND speed3 <> speed2 AND speed3 <> speed)πmakerExercise 2.4.2kπmaker(maker4 = maker AND (model4=model OR model4=model2 OR model4=model3)) (maker3 = maker AND model3 <> model2 AND model3 <> model)(maker = maker2 AND model <> model2)ρR2(maker2,model2)ρR3(maker3,model3)ρR4(maker4,model4)πmaker,modelProduct PCExercise 2.4.3aR1 := σbore ≥ 16 (Classes)R2 := πclass,country (R1)Exercise 2.4.3bR1 := σlaunched < 1921 (Ships)R2 := πname (R1)KirishimaKongoRamilliesRenownRepulseResolutionRevengeRoyal OakRoyal SovereignTennesseeExercise 2.4.3cR1 := σbattle=Denmark Strait AND result=sunk(Outcomes)R2 := πship (R1)shipBismarckHoodExercise 2.4.3dR1 := Classes ShipsR2 := σlaunched > 1921 AND displacement > 35000 (R1)R3 := πname (R2)nameIowaMissouriMusashiNew JerseyNorth CarolinaWashingtonWisconsinYamatoExercise 2.4.3eR1 := σbattle=Guadalcanal(Outcomes)R2 := Ships (ship=name) R1R3 := Classes R2R4 := πname,displacement,numGuns(R3)name displacement numGuns Kirishima 32000 8Washington 37000 9Exercise 2.4.3fR1 := πname(Ships)R2 := πship(Outcomes)R3 := ρR3(name)(R2)R4 := R1 R3nameCaliforniaHarunaHieiIowaKirishimaKongoMissouriMusashiNew JerseyExercise 2.4.3gFrom 2.3.2, assuming that every class has one ship named after the class.R1 := πclass (Classes) R2 := πclass (σname <> class (Ships)) R3 := R1 – R2Exercise 2.4.3hR1 := πcountry (σtype=bb (Classes)) R2 := πcountry (σtype=bc (Classes)) R3 := R1 ∩ R2Exercise 2.4.3iR1 := πship,result,date (Battles (battle=name) Outcomes)R2 := ρR2(ship2,result2,date2)(R1)R3 := R1 (ship=ship2 AND result=damaged AND date < date2) R2R4 := πship (R3)No results from sample data.Exercise 2.4.4aσbore ≥ 16πclass,countryClassesExercise 2.4.4bNorth Carolina Ramillies Renown Repulse Resolution Revenge Royal Oak Royal Sovereign Tennessee Washington Wisconsin Yamato Arizona Bismarck Duke of York Fuso Hood King George V Prince of Wales Rodney Scharnhorst South Dakota West Virginia Yamashiro class Bismarck country Japan Gt. Britainπnameσlaunched < 1921ShipsExercise 2.4.4cπshipσbattle=Denmark Strait AND result=sunkOutcomesExercise 2.4.4dπnameσlaunched > 1921 AND displacement > 35000Classes Ships Exercise 2.4.4eσbattle=Guadalcanal Outcomes Ships(ship=name)πname,displacement,numGunsExercise 2.4.4f Ships Outcomesπnameπship ρR3(name)Exercise 2.4.4g Classes Shipsπclass σname <> class πclass–Exercise 2.4.4hClasses Classesσtype=bb σtype=bcπcountry πcountry∩Exercise 2.4.4iBattles Outcomes (battle=name)πship,result,dateρR2(ship2,result2,date2)(ship=ship2 AND result=damaged AND date < date2)πshipExercise 2.4.5The result of the natural join has only one attribute from each pair of equated attributes. On the other hand, the result of the theta-join has both columns of the attributes and their values are identical.Exercise 2.4.6UnionIf we add a tuple to the arguments of the union operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple is a duplicate tuple, then the set behavior will eliminate that tuple.Thus the union operator is monotone.IntersectionIf we add a tuple to the arguments of the intersection operator, we will get all of the tuples of the originalresult and maybe the added tuple. If the added tuple does not exist in the relation that it is added but does exist in the other relation, then the result set will include the added tuple. Thus the intersection operator is monotone.DifferenceIf we add a tuple to the arguments of the difference operator, we may not get all of the tuples of the originalresult. Suppose we have relations R and S and we are computing R – S. Suppose also that tuple t is in R but not in S. The result of R – S would include tuple t. However, if we add tuple t to S, then the new result will not have tuple t. Thus the difference operator is not monotone.ProjectionIf we add a tuple to the arguments of the projection operator, we will get all of the tuples of the original result and the projection of the added tuple. The projection operator only selects columns from the relation and does not affect the rows that are selected. Thus the projection operator is monotone.SelectionIf we add a tuple to the arguments of the selection operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple satisfies the select condition, then it will be added to the newresult. The original tuples are included in the new result because they still satisfy the select condition. Thusthe selection operator is monotone.Cartesian ProductIf we add a tuple to the arguments of the Cartesian product operator, we will get all of the tuples of the original result and possibly additional tuples. The Cartesian product pairs the tuples of one relation with the tuples ofanother relation. Suppose that we are calculating R x S where R has m tuples and S has n tuples. If we add a tuple to R that is not already in R, then we expect the result of R x S to have (m + 1) * n tuples. Thus the Cartesianproduct operator is monotone.Natural JoinsIf we add a tuple to the arguments of a natural join operator, we will get all of the tuples of the original result and possibly additional tuples. The new tuple can only create additional successful joins, not less. If, however, the added tuple cannot successfully join with any of the existing tuples, then we will have zero additionalsuccessful joins. Thus the natural join operator is monotone.Theta JoinsIf we add a tuple to the arguments of a theta join operator, we will get all of the tuples of the original result and possibly additional tuples. The theta join can be modeled by a Cartesian product followed by a selection onsome condition. The new tuple can only create additional tuples in the result, not less. If, however, the addedtuple does not satisfy the select condition, then no additional tuples will be added to the result. Thus the theta join operator is monotone.RenamingIf we add a tuple to the arguments of a renaming operator, we will get all of the tuples of the original result and the added tuple. The renaming operator does not have any effect on whether a tuple is selected or not. In fact, the renaming operator will always return as many tuples as its argument. Thus the renaming operator is monotone.Exercise 2.4.7aIf all the tuples of R and S are different, then the union has n + m tuples, and this number is the maximum possible.The minimum number of tuples that can appear in the result occurs if every tuple of one relation also appears in the other. Then the union has max(m , n) tuples.Exercise 2.4.7bIf all the tuples in one relation can pair successfully with all the tuples in the other relation, then the natural join has n * m tuples. This number would be the maximum possible.The minimum number of tuples that can appear in the result occurs if none of the tuples of one relation can pairsuccessfully with all the tuples in the other relation. Then the natural join has zero tuples.Exercise 2.4.7cIf the condition C brings back all the tuples of R, then the cross product will contain n * m tuples. This number would be the maximum possible.The minimum number of tuples that can appear in the result occurs if the condition C brings back none of the tuples of R. Then the cross product has zero tuples.Exercise 2.4.7dAssuming that the list of attributes L makes the resulting relation πL(R) and relation S schema compatible, then the maximum possible tuples is n. This happens when all of the tuples of πL(R) are not in S.The minimum number of tuples that can appear in the result occurs when all of the tuples in πL(R) appear in S. Then the difference has max(n–m , 0) tuples.Exercise 2.4.8Defining r as the schema of R and s as the schema of S:1.πr(R S)2.R δ(πr∩s(S)) where δ is the duplicate-elimination operator in Section 5.2 pg. 2133.R – (R –πr(R S))Exercise 2.4.9Defining r as the schema of R1.R - πr(R S)Exercise 2.4.10πA1,A2…An(R S)Exercise 2.5.1aσspeed < 2.00 AND price > 500(PC) = øModel 1011 violates this constraint.Exercise 2.5.1bσscreen < 15.4 AND hd < 100 AND price ≥ 1000(Laptop) = øModel 2004 violates the constraint.Exercise 2.5.1cπmaker(σtype = laptop(Product)) ∩ πmaker(σtype = pc(Product)) = øManufacturers A,B,E violate the constraint.Exercise 2.5.1dThis complex expression is best seen as a sequence of steps in which we define temporary relations R1 through R4 that stand for nodes of expression trees. Here is the sequence:R1(maker, model, speed) := πmaker,model,speed(Product PC)R2(maker, speed) := πmaker,speed(Product Laptop)R3(model) := πmodel(R1 R1.maker = R2.maker AND R1.speed ≤ R2.speed R2)R4(model) := πmodel(PC)The constraint is R4 ⊆ R3Manufacturers B,C,D violate the constraint.Exercise 2.5.1eπmodel(σLaptop.ram > PC.ram AND Laptop.price ≤ PC.price(PC × Laptop)) = øModels 2002,2006,2008 violate the constraint.Exercise 2.5.2aπclass(σbore > 16(Classes)) = øThe Yamato class violates the constraint.Exercise 2.5.2bπclass(σnumGuns > 9 AND bore > 14(Classes)) = øNo violations to the constraint.Exercise 2.5.2cThis complex expression is best seen as a sequence of steps in which we define temporary relations R1 through R5 that stand for nodes of expression trees. Here is the sequence:R1(class,name) := πclass,name(Classes Ships)R2(class2,name2) := ρR2(class2,name2)(R1)R3(class3,name3) := ρR3(class3,name3)(R1)R4(class,name,class2,name2) := R1 (class = class2 AND name <> name2) R2R5(class,name,class2,name2,class3,name3) := R4 (class=class3 AND name <> name3 AND name2 <> name3) R3The constraint is R5 = øThe Kongo, Iowa and Revenge classes violate the constraint.Exercise 2.5.2dπcountry(σtype = bb(Classes)) ∩ πcountry(σtype = bc(Classes)) = øJapan and Gt. Britain violate the constraint.Exercise 2.5.2eThis complex expression is best seen as a sequence of steps in which we define temporary relations R1 through R5 that stand for nodes of expression trees. Here is the sequence:R1(ship,bat tle,result,class) := πship,battle,result,class(Outcomes (ship = name) Ships)R2(ship,battle,result,numGuns) := πship,battle,result,numGuns(R1 Classes)R3(ship,battle) := πship,battle(σnumGuns < 9 AND result = sunk (R2))R4(ship2,battle2) := ρR4(ship2,battle2)(πship,battle(σnumGuns > 9(R2)))R5(ship2) := πship2(R3 (battle = battle2) R4)The constraint is R5 = øNo violations to the constraint. Since there are some ships in the Outcomes table that are not in the Ships table, we are unable to determine the number of guns on that ship.Exercise 2.5.3Defining r as the schema A1,A2,…,A n and s as the schema B1,B2,…,B n:πr(R) πs(S) = øwhere is the antisemijoinExercise 2.5.4The form of a constraint as E1 = E2 can be expressed as the other two constraints.Using the “equating an expression to the empty set” method, we can simply say:E1– E2 = øAs a containment, we can simply say:E1⊆ E2 AND E2⊆ E1Thus, the form E1 = E2 of a constraint cannot express more than the two other forms discussed in this section.。
数据库管理软件实战案例分享Introduction在当今信息化时代,数据库管理软件已经成为企业管理数据的重要工具。
通过数据库管理软件,企业可以高效地存储、管理和分析大量的数据。
本文将分享一些实战案例,介绍不同行业中使用的数据库管理软件,以及它们在各个领域的应用。
Chapter 1: 银行行业中的数据库管理软件应用在银行行业,数据库管理软件被广泛用于存储和管理客户账户信息、交易记录等。
通过这些软件,银行可以实现对海量数据的高速查询和分析,从而提高核心业务的运营效率。
本章将介绍几个数据库管理软件在银行行业中的实际应用案例。
Chapter 2: 零售行业中的数据库管理软件应用零售行业的数据库管理软件用于存储和管理销售数据、库存信息、客户信息等。
通过这些软件,零售商可以对销售趋势、产品热度等进行分析,以便做出更准确的业务决策。
本章将介绍几个数据库管理软件在零售行业中的实际应用案例。
Chapter 3: 制造业中的数据库管理软件应用在制造业中,数据库管理软件被用于存储和管理物料清单、生产进度、质量数据等。
通过这些软件,制造商可以实现对生产过程的监控和优化,从而提高生产效率和产品质量。
本章将介绍几个数据库管理软件在制造业中的实际应用案例。
Chapter 4: 医疗行业中的数据库管理软件应用医疗行业中的数据库管理软件被广泛用于存储和管理患者病历、医疗记录、药物信息等。
通过这些软件,医疗机构可以实现对患者数据的快速访问和分析,提高临床决策的准确性。
本章将介绍几个数据库管理软件在医疗行业中的实际应用案例。
Chapter 5: 教育行业中的数据库管理软件应用在教育行业中,数据库管理软件被广泛用于学生信息管理、教学资源管理等。
通过这些软件,学校可以实现对学生和教学数据的集中管理和分析,促进教学质量的提升。
本章将介绍几个数据库管理软件在教育行业中的实际应用案例。
Conclusion通过以上实战案例的分享,我们可以看到数据库管理软件在不同领域中的广泛应用。
第2章 关系数据库系统关系数据库系统(RelationalDataBaseManaqementSystem,RDBMS)以其结构简单、通俗易懂、使用方便等特点,深受广大用户的欢迎,是目前使用最广泛的数据库系统。
本章介绍关系模型和关系数据库的基本概念,包括关系数据结构、关系操作和关系完整性。
2畅1 关系数据库系统概述关系模型是由IBM公司的埃德加・科德于1970年首先提出的。
关系模型中无论是实体还是实体间的联系均由关系来表示。
关系数据库是建立在关系模型基础上的数据库。
关系模型由关系数据结构、关系操作集合、关系完整性约束三部分组成。
2畅1畅1 关系数据结构关系模型的数据结构很单一,在用户看来,关系模型中数据的逻辑结构是一张二维表。
关系模型的数据结构和基本术语如下所述。
1畅域一组具有相同数据类型的值的集合。
如表2畅1学生基本信息表Table_Student中Sex(性别)的取值为“F”或“M”,其域为{"F","M"}。
2畅笛卡儿积给定一组域D1,D2,…,Dn,这些域中可以有相同的。
D1,D2,…,Dn的笛卡儿积为D1×D2×…×Dn={(d1,d2,…,dn)dj∈Dj,j=1,2,…,n}。
其中,每一个元素(d1,d2,…,dn)称为一个n元组(简称为元组)。
元组中的每一个值dj称为一个分量。
3畅关系D1×D2×…×Dn的子集称为在域D1,D2,…,Dn上的关系,用R(D1,D2,…,Dn)表示。
这里R表示关系的名字,n是关系的目或度。
关系中的每个元素是关系中的元组,通常用t表示。
关系是笛卡儿积的子集,所以关系也是一个二维表,表的每行对应一个元组,表的每列对应一个域。
由于域可以相同,为了加以区分,二维表的每列称为一个属性。
每一列有一个属性名,且属性不能重名。
属性值是属性的具体值。
表2畅1就是一个关系的实例,关系名为Table_Student(学生基本信息表),存储饭卡数据库管理系统中的学生基本信息。
表2畅1只有四个元组,显示了四名学生的信息。
表2畅1有五个属性,分别是StudentID(学号)、CardID(饭卡号)、Sname(姓名)、Sex(性别)和School(学院)。
表2畅1 学生基本信息表Table_StudentStudentIDCardIDSnameSexSchool01200502000025685234王俊F管理学院01200502000125685236李伟M管理学院01200502385235862578陈文M软件学院01200502458356987435张钰F环境学院4畅关系模式对关系的信息结构及语法限制的描述称为关系模式。
关系模式用关系名和包含的属性名的集合表示。
用括号把属性集括起来,并把关系名写在括号的前面表示关系的模式。
于是,表2畅1中的Table_Student(学生基本信息表)的关系模式就是:Table_Student(StudentID,CardID,Sname,Sex,School)注意:关系模式中的属性是一个集合,而不是列表。
在关系模型中,数据库设计包含一个或多个关系模式。
所涉及的关系模式的集合称为“关系数据库模式”,或简称为“数据库模式”。
5畅关键字在关系的诸属性中,能够用来唯一标识元组的属性或属性组合的称为关键字或码。
在一个关系中,码的取值不能为空。
表2畅1中关系的码为StudentID这个属性。
关系模式中,若单个属性是码,称为单码(SingleKey);极端情况下,整个属性组是码,称为全码(AllKey)。
【例2‐1】 在饭卡管理系统中,关系模式操作(操作人员编号,售饭机编号,操作日期)中,每个操作人员可以操作多台售饭机,每台售饭机可以被多个操作人员操作,而每个操作人员对每台售饭机又可以进行多次操作,因此,单个属性(操作人员编号、售饭机编号、操作日期)或两个属性组合(操作人员编号,售饭机编号)、(售饭机编号,操作日期)、(操作人员编号,操作日期)等均不能完全决定某个元组,只有(操作人员编号,售饭机编号,操作日期)才能唯一确定某个元组,所以这个模式的码为(操作人员编号,售饭机编号,操作日期),即全码。
6畅候选关键字如果在一个关系中,存在多个属性(或属性组合)都能用来唯一标识元组,这些属性(或属性组合)都可以作为候选关键字或候选码。
表2畅1中,由于Stu‐dentID和CardID都是每个学生唯一拥有的,即根据这两个属性都可以唯一确定一个学生。
因此,属性StudentID和CardID都可作为候选关键字。
7畅主关键字在一个关系的若干候选关键字中,被指定作为关键字的候选关键字称为该关系的主关键字(PrimaryKey)或主码。
表2畅1中的主关键字或主码是StudentID这个属性。
8畅主属性与非主属性包含在任一候选码中的属性,叫做主属性(PrimeAttribute);不包含在任何候选码中的属性称为非主属性(NonPrimeAttribute)或非码属性(NonKeyAttribute)。
表2畅1中,StudentID、CardID都是主属性。
Sname、Sex和School就是这个关系的非主属性。
9畅外部关键字设有两个关系模式R和S,F是R的一个或一组属性,但不是R的码,如果F与基本关系S的主码KS相对应,则称F是R的外部关键字或外部码(For‐eignKey),简称外码。
并称基本关系R为参照关系(ReferencingRelation),或从表,基本关系S为被参照关系(ReferencedRelation)、目标关系(TargetRe‐lation)或主表。
关系R和S不一定是不同的关系,但是KS与F是定义在同一域中的。
【例2‐2】 在关系学生(学号、饭卡号、姓名、性别、院系)中,饭卡号不是主码,但饭卡号是关系饭卡(饭卡号,密码,办卡日期,注销日期,状态,余额)的主码,则饭卡号是关系学生的外码。
关系饭卡是主表,关系学生是从表。
主码除了唯一标识一个实体之外,常常与外码构成参照完整性约束,防止出现数据不一致。
主码和外码提供了一个表示关系间联系的手段。
关系学生和饭卡之间的联系就是通过饭卡号这个在学生关系中是外码又在饭卡关系中是主码的属性来体现的。
2畅1畅2 基本关系的性质关系与二维表及传统的数据文件有类似之处,但也有区别。
关系是一种规范化的二维表,作为关系的二维表必须满足下列六条性质。
1)同一属性(列)中的分量是相同类型的数据,即取自同一个域。
2)属性(列)的顺序可以是任意的。
3)元组(行)的顺序可以是任意的。
4)任意两个元组(即两行)不能完全相同。
5)属性必须有不同的名称,但不同的属性可以取自相同的域。
6)所有属性必须都是不可分解的,即表中不允许有子表。
2畅1畅3 关系模式的定义关系模式是对关系的描述,是一个关系的具体结构。
一个关系模式应当是一个五元组。
它通常被形式化定义为R(U,D,DOM,F,I)。
其中R是关系名,U为该关系中的所有属性集合;D为该关系的所有定义域的集合;DOM是属性向域映射的集合,它给出属性和域之间的对应关系;F是该关系中各属性之间的数据依赖的集合;I为该关系中所定义的完整性规则的集合。
在数据库系统中定义一个关系模式时,主要是给出关系名和所有属性名,其他都是辅助特性。
例如,属性的域被作为属性的类型和长度来定义,其中自然包含了属性向域的映射,属性之间的数据依赖的分析主要是找出关系的主键属性,关系的完整性规则的建立则是为了保证数据库数据的正确性和一致性。
因此,一个关系模式可以简化表示为R(A1,A2,…,An),其中R为关系名,A1,A2,…,An为各属性名。
关系实际上就是关系模式在某一时刻的状态或内容。
也就是说,关系模式是型,关系是它的值。
关系模式是静态的、稳定的,而关系是动态的、随时间不断变化的,因为关系操作在不断地更新着数据库中的数据。
但在实际当中,常常把关系模式和关系统称为关系,读者可以从上下文中加以区别。
2畅1畅4 关系数据库在关系模型中,实体及实体间的联系都是用关系来表示的。
在一个给定的现实世界领域中,相应于所有实体及实体之间的联系的关系集合构成一个关系数据库。
关系数据库也有型和值之分。
关系数据库的型也称为关系数据库模式,是对关系数据库的描述,是关系模式的集合。
关系数据库的值也称为关系数据库,是关系的集合。
关系数据库模式与关系数据库通常统称为关系数据库。
2畅2 实体联系模型转换为关系模型实体联系模型(EntityRelationModel,E‐R模型)提供了表示实体型、属性和联系的方法,用来描述现实世界的概念模型。
E‐R模型和关系模型术语的对应关系见表2畅2。
表2畅2 E‐R模型与关系模型术语的对应关系E‐R模型关系模型实体关系(表)实体实例元组(行)联系关系(表)属性属性(列)属性值元组分量(列值)E‐R模型向关系模型的转换,实际上就是要将实体、属性和联系转化为关系模式,转换规则包括以下七点。
1)一个实体型转换为一个同名的关系模式。
实体的属性就是关系的属性,实体的码就是关系的码。
2)一个1∶1联系可以转换为一个独立的关系模式,也可以与任意一端对应的关系模式合并,该联系的码可以是任一端的实体的码。
3)一个1∶n联系可以转换为一个独立的关系模式,也可以与n端对应的关系模式合并,则n端实体的码就是该联系的码。
4)一个m∶n联系转换为一个关系模式,与该联系相连的各实体的码的集合就是该联系的码。
5)三个或三个以上实体间的一个多元联系转换为一个关系模式。
6)同一实体集的实体间的联系,即自联系,也可按上述1∶1、1∶n和m∶n三种情况分别处理。
7)具有相同码的关系模式可以合并。
下面根据上述转换规则,将第1章最后介绍的案例及例1‐1和例1‐2的E‐R模型转换成关系模式。
【例2‐3】 将第1章建立的饭卡管理系统的E‐R模型,如图1畅22所示,转化成关系模式。
转化步骤如下所述。
1畅标示E‐R模型中的联系饭卡管理涉及三个联系:“使用”联系、“消费”联系和“操作”联系。
2畅依次转换与每个联系相关联的实体及联系(1)联系“使用”的转换过程在“使用”联系中共有两个实体:“学生”实体和“饭卡”实体,其联系的类型是1∶1,根据转换规则得下列关系。
关系1:学生(学号,姓名,性别,院系)关系2:饭卡(饭卡号,密码,办卡日期,注销日期,状态,余额)注意:上述两个关系都是由转换规则1得到。
关系3:使用(学号、饭卡号)注意:由转换规则2得到。
再由转换规则7,将关系1和关系3合并得到:关系4:学生(学号,饭卡号,姓名,性别,院系)(2)“消费”联系的转换过程在“消费”联系中共有三个实体:“饭卡”实体、“消费记录”实体和“售饭机”实体,是三个实体间的多元联系,根据转换规则得下列关系。