1. 程式人生 > >數據系統結構之關系操作(翻譯)

數據系統結構之關系操作(翻譯)

pair set info cin several always dup similar data

Published by McGraw-Hill, a business unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the Americas, New York, NY 10020. Copyright ? 2011 by The McGraw-Hill Companies, Inc.

All rights reserved. Previous editions ? 2006, 2002, and 1999.

此文為自己的翻譯譯文,上文為原文鏈接,如有雷同,敬請諒解

Relational Operations

關系操作

All procedural relational query languages provide a set of operations that

can be applied to either a single relation or a pair of relations.

所有的程序上的關系運算語言都提供了一系列可以應用於單方面或者是雙方的關系運算

所有的過程關系查詢語言都提供了一組操作可以應用於單個關系或一對關系。

These operations have the nice and desired property that their result is always a single relation.

這些操作具有良好的和所需的屬性,它們的結果始終是單個關系。

This property allows one to combine several of these operations in a modular way.

在某種程度上,這個屬性可以允許一種運算結合另外集中運算

此屬性允許以模塊方式組合多個操作。

Specifically, since the result of a relational query is itself a relation, relational operations can be applied to the results of queries as well as to the given set of relations.

具體來說,由於關系查詢的結果本身就是一個關系,因此關系操作可以應用於查詢的結果以及給定的關系集

The specific relational operations are expressed differently depending on the language, but fit the general framework we describe in this section.

那個特別的關系操作根據不同語言不同地表達,但是符合我們在這個部分表達的總體結構

In Chapter 3, we show the specific way the operations are expressed in SQL .

在第三章,我們展示了操作關系在SQL中的表達

The most frequent operation is the selection of specific tuples from a sin-

gle relation (say instructor) that satisfies some particular predicate (say salary >$85,000).

最常見的操作就是從一個部分中選擇特定的元組關系(比如講師),它滿足某些特定的謂詞(比如$ 85,000)

The result is a new relation that is a subset of the original relation。

結果就是,新的關系就是一個最初的操作子集入手

Figure 2.10 Result of query selecting instructor tuples with salary greater than $85000. structor).

關系查詢引導教師薪資大於85000美元

For example, if we select tuples from the instructor relation of Figure 2.1, satisfying the predicate salary is greater than $85000, we get the result shown in Figure 2.10.

例如,如果我們從教師關系表2.1挑選符合條件(薪資大於85000美元)的,我們會從表格2.10獲得結果

Another frequent operation is to select certain attributes (columns) from a relation.

另外一個操作就是從關系表中選擇確定的元素

The result is a new relation having only those selected attributes.

結果是一個新的只有被選出來的關系

For example, suppose we want a list of instructor ID s and salaries without listing the name and dept name values from the instructor relation of Figure 2.1, then the result, shown in Figure 2.11, has the two attributes ID and salary.

例如,假設我們不用從關系表格2.1列出名字和部門名字就可以得到一系列的教師身份證和薪水,並把這些體現在表格2.11

Each tuple in the result is derived from a tuple of the instructor relation but with only selected attributes shown.

在結果中每個教師被從一個教師關系表格但是只有被挑選到的會顯現

The join operation allows the combining of two relations by merging pairs of tuples, one from each relation, into a single tuple.

那個聯結的操作允許兩個關系結合在一起,每個關系從很多關系而來,只記錄在一個表格

There are a number of different ways to join relations (as we shall see in Chapter3).

有很多不同方法去結合關系,就像我們在第三章看見的那樣

Figure2.12 shows an example of joining the tuples from the instructor and department tables with the new tuples showing the information about each instructor and the department in which she is working.

表格2.12展示了一個把從教師和公寓表格組成一個新的表格,可以展示每個教師和他在哪兒工作

This result was formed by combining each tuple in the instructor relation with the tuple in the department relation for the instructors department.

這個結果由每個展示教師關系的表格結合而成,每個表格都展示了部門關系中教師部門

In the form of join shown in Figure 2.12, which is called a natural join, a tuple from the instructor relation matches a tuple in the department relation if the values .

在表格的自然連接中,如果可以的話,一個表格的教師關系可以匹配一個部門的關系表格

Figure 2.11 Result of query selecting attributes ID and salary from the instructor relation.

表格2.11是從教師關系中查詢身份證和薪水

Figure 2.12 Result of natural join of the instructor and department relations.of their dept name attributes are the same.

表格2.12把教師和部門的連接表格部門名字相同

All such matching pairs of tuples are present in the join result.

每個匹配的元組都代表連接結果

In general, the natural join operation on two relations matches tuples whose values are the same on all attribute names that are common to both relations.

總之,一般來說,兩種關系的自然連接操作都匹配tuple,它們的值對於兩種關系中的所有屬性名稱都是相同的。

The Cartesian product operation combines tuples from two relations,but unlike the join operation, its result contains all pairs of tuples from the two relations,regardless of whether their attribute values match.

The Cartesian產品操作結合兩個操作,但是不像連接操作,它的結果包括所有從兩個表格選的元組,除了他們匹配的屬性值

Because relations are sets, we can perform normal set operations on relations.

因為操作已經完成,我們可以在關系上展示正常操作

The union operation performs a set union of two similarly structuredtables(say a table of all graduate students and a table of all undergraduate students)

聯合操作展示了一種兩個相似結構表格聯合(就是一個畢業學生和在校學生的表格)

.For example, one can obtain the set of all students in a department. Other set operations, such as intersection and set difference can be performed as well.

例如,一個可以包括一個部門裏的所有學生,其他的操作,比如交集和不同也可以很好呈現

As we noted earlier, we can perform operations on the results of queries.

就像我們之前提到的,我們可以在查詢結果中操作

For example,if we want to find the ID and salary for those instructors who have salary greater than $85,000, we would perform the first two operations in our example above.

例如,我們想要查詢身份證和薪水超過85000美元的教師,我們可以輸入上文上個例子的操作

First we select those tuples from the instructor relation where the salary value is greater than $85,000 and then, from that result, select the two attributes ID and salary, resulting in the relation shown in Figure 2.13 consisting of the ID

第一我們可以從那些關系表格選擇符合條件的元組,然後從結果選擇兩個身份屬性和薪水,最後展現在表格2.13

2.6 Relational Operations 51

2.6關系操作

RELATIONAL ALGEBRA

關系代數

The relational algebra defines a set of operations on relations, paralleling the usual algebraic operations such as addition,subtraction or multiplication,which operate on numbers.

關系代數定義了一系列的關系操作,將通常的代數運算,例如加法、減法運算和乘法運算,並聯在數字上。

Just as algebraic operations on numbers take one or more numbers as input and return a number as output, the relational algebra operations typically take one or two relations as input and return a relation as output.

只是一個或多個數字上的代數操作,關系代數操作通常花費一個或者兩個關系像輸入和輸出一個關系

Relational algebra is covered in detail in Chapter 6, but we outline a few of the operations below and salary.

第六章覆蓋了關系代數,但是我們只列出一下以下的操作

In this example, we could have performed the operations in either order, but that is not the case for all situations, as we shall see.

在這個例子當中,我們可以在另外的命令中操作但是這不是所有我們看到的例子

Sometimes,the result of a query contains duplicate tuples.

有時查詢結果包含了元組

For example, if we select the dept name attribute from the instructor relation, there are several cases of duplication, including Comp. Sci., which shows up three times.

例如,如果我們從教師選擇部門名字屬性從教師關系表,有一些是很少的重復,包括出現了三次的Comp. Sci.

Certain relational languages adhere strictly to the mathe matical definition of a set and remove duplicates.

某些關系語言嚴格遵守設置的mathe matical定義,並刪除重復。

Others, in consideration of the relatively large amount of processing required to remove duplicates from large result relations, retain duplicates.

其他的,考慮到相對較大的程序要求去移出重復

In these latter cases, the relations are not truly relations in the pure mathematical sense of the term.

在這些例子當中,關系不僅是完全數學物品關系

Of course, data in a database must be changed over time.

當然,在數據庫的數據一定會一直改變

A relation can be updated by inserting new tuples, deleting existing tuples, or modifying tuples by 52 Chapter 2 Introduction to the Relational Model changing the values of certain attributes.

一個關系表可以保存插入的新元組

Entire relations can be deleted and new ones created.

整個關系可以被刪除或重建

We shall discuss relational queries and updates using the SQL language in Chapters 3 through 5.

我們會在第三章到第五章討論關系查詢和存儲用SQL語言

Summary

總結

? The relational data model is based on a collection of tables.

關系數據模型是基於表格收集

The user of the database system may query these tables, insert new tuples, delete tuples, and update (modify) tuples.

數據庫系統的使用查詢這些表格,插入新元組,刪除元組和下載元組

There are several languages for expressing these operations.

這些事解釋這些操作的語言

? The schema of a relation refers to its logical design, while an instance of the relation refers to its contents at a point in time.

?關系的圖式是指它的邏輯設計,而關系的實例指的是它在某一時刻的內容。

The schema of a database and an instance of a database are similarly defined.

同樣定義了數據庫的模式和數據庫的實例。

The schema of a relation include sits attributes, and optionally the types of the attributes and constraints on the relation such as primary and foreign key constraints.

關系的模式包括屬性,以及可選的屬性類型和約束關系,如主鍵和外鍵約束。

? A superkey of a relation is a set of one or more attributes whose values are guaranteed to identify tuples in the relation uniquely.

一個超碼的關系是一個或多個屬性的值被保證去認定元組

A candidate key is a minimal superkey, that is, a set of attributes that forms a superkey, but none of whose subsets is a superkey.

一個候選人是一個重要的主鍵,就是一個表格的屬性,但是沒有任何一個子集是主鍵

One of the candidate keys of a relation is chosen as its primary key.

其中的候選鍵是從主鍵選出來的

? A foreign key is a set of attributes in a referencing relation, such that for each tuple in the referencing relation, the values of the foreign key attributes are guaranteed to occur as the primary key value of a tuple in the referenced relation.

外鍵是一系列關系中的屬性,在關系中的各個元組,外鍵的值的屬性要一定是元組的主鍵

? A schema diagram is a pictorial depiction of the schema of a database that shows the relations in the database, their attributes, and primary keys and foreign keys.

?模式圖是一個數據庫模式的圖形描述,它顯示數據庫中的關系、它們的屬性、主鍵和外鍵。

? The relational query languages define a set of operations that operate on tables, and output tables as their results.

關系查詢語言定義了一系列的操作,作用於表格和結果的表格

These operations can be combined to get expressions that express desired queries.

這些操作可以被組合去得到查詢表達

? The relational algebra provides a set of operations that take one or more relations as input and return are lationasan output.

?關系代數提供了一組操作,它們以一個或多個關系作為輸入,而返回是lationasan輸出。

Practical query 實用查詢

Languages such as SQL are based on the relational algebra, but add a number of useful syntactic features.

像基於關系代數的SQL語言,但是加入了一系列的有用的元素

數據系統結構之關系操作(翻譯)