正在加载图片...
Appendix C Other Relational Query Languages 2.QBE queries are expressed"by example."Instead of giving a procedure for obtaining the desired answer,the user gives an example of what is desired. The system generalizes this example to compute the answer to the query. Despite these unusual features,there is a close correspondence between QBE and the domain relational calculus. There are two flavors of QBE:the original text-based version and a graphical version developed later that is supported by the Microsoft Access database sys- tem.In this section we provide a brief overview of the data-manipulation features of both versions of QBE.We first cover features of the text-based QBE that corre- spond to the SQL select-from-where clause without aggregation or updates.See the bibliographical notes for references where you can obtain more information about how the text-based version of QBE handles sorting of output,aggregation, and update. C.1.1 Skeleton Tables We express queries in QBE by skeleton tables.These tables show the relation schema,as in Figure C.1.Rather than clutter the display with all skeletons,the user selects those skeletons needed for a given query and fills in the skeletons with example rows.An example row consists of constants and example elements, which are domain variables.To avoid confusion between the two,QBE uses an underscore character (_)before domain variables,as in _x,and lets constants appear without any qualification.This convention is in contrast to those in most other languages,in which constants are quoted and variables appear without any qualification. C.1.2 Queries on One Relation Returning to our ongoing bank example,to find all loan numbers at the Perryridge branch,we bring up the skeleton for the loan relation,and fill it in as follows: loan loan_number branch_name a1o1411t P._x Perryridge This query tells the system to look for tuples in loan that have"Perryridge"as the value for the branch name attribute.For each such tuple,the system assigns the value of the loan-number attribute to the variable x.It"prints"(actually,displays) the value of the variable x,because the command P.appears in the loan number column next to the variable x.Observe that this result is similar to what would be done to answer the domain-relational-calculus query {(x)I3b,a(x,b,a)∈loan A b=“Perryridge")月 QBE assumes that a blank position in a row contains a unique variable.As a result,if a variable does not appear more than once in a query,it may be omitted. Our previous query could thus be rewritten as2 Appendix C Other Relational Query Languages 2. QBE queries are expressed “by example.” Instead of giving a procedure for obtaining the desired answer, the user gives an example of what is desired. The system generalizes this example to compute the answer to the query. Despite these unusual features, there is a close correspondence between QBE and the domain relational calculus. There are two flavors of QBE: the original text-based version and a graphical version developed later that is supported by the Microsoft Access database sys￾tem. In this section we provide a brief overview of the data-manipulation features of both versions of QBE. We first cover features of the text-based QBE that corre￾spond to the SQL select-from-where clause without aggregation or updates. See the bibliographical notes for references where you can obtain more information about how the text-based version of QBE handles sorting of output, aggregation, and update. C.1.1 Skeleton Tables We express queries in QBE by skeleton tables. These tables show the relation schema, as in Figure C.1. Rather than clutter the display with all skeletons, the user selects those skeletons needed for a given query and fills in the skeletons with example rows. An example row consists of constants and example elements, which are domain variables. To avoid confusion between the two, QBE uses an underscore character ( ) before domain variables, as in x, and lets constants appear without any qualification. This convention is in contrast to those in most other languages, in which constants are quoted and variables appear without any qualification. C.1.2 Queries on One Relation Returning to our ongoing bank example, to find all loan numbers at the Perryridge branch, we bring up the skeleton for the loan relation, and fill it in as follows: loan loan_number branch_name amount P. x Perryridge This query tells the system to look for tuples in loan that have “Perryridge” as the value for the branch name attribute. For each such tuple, the system assigns the value of the loan number attribute to the variable x. It “prints” (actually, displays) the value of the variable x, because the command P. appears in the loan number column next to the variable x. Observe that this result is similar to what would be done to answer the domain-relational-calculus query {x|∃ b, a(x, b, a ∈ loan ∧ b = “Perryridge”)} QBE assumes that a blank position in a row contains a unique variable. As a result, if a variable does not appear more than once in a query, it may be omitted. Our previous query could thus be rewritten as
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有