正在加载图片...
C.3 Datalog 11 in the row"Total."Such"Where"selections are applied before aggregation,and correspond to selections in an SQL where clause.However,such columns cannot be printed (marked as"Show").Only columns where the "Total"row specifies either"group by,"or an aggregate function can be printed. Queries are created through a graphical user interface,by first selecting tables. Attributes can then be added to the design grid by dragging and dropping them from the tables.Selection conditions,grouping,and aggregation can then be specified on the attributes in the design grid.Access QBE supports a number of other features too,including queries to modify the database through insertion, deletion,or update. C.3 Datalog Datalog is a nonprocedural query language based on the logic-programming language Prolog.As in the relational calculus,a user describes the information desired without giving a specific procedure for obtaining that information.The syntax of Datalog resembles that of Prolog.However,the meaning of Datalog programs is defined in a purely declarative manner,unlike the more procedural semantics of Prolog,so Datalog simplifies writing simple queries and makes query optimization easier. C.3.1 Basic Structure A Datalog program consists of a set of rules.Before presenting a formal definition of Datalog rules and their formal meaning,we consider examples.Consider a Datalog rule to define a view relation o1 containing account numbers and balances for accounts at the Perryridge branch with a balance of over $700: v1(A,B):-account(A,"Perryridge",B),B>700 Datalog rules define views;the preceding rule uses the relation account,and defines the view relation 01.The symbol :is read as"if,"and the comma separating the“account(A,Perryridge'”,B)'from“B>T0o'is read as“and.” Intuitively,the rule is understood as follows: for all A,B if(A,Perryridge'”,B)∈account and B>700 then(A,B)∈o1 Suppose that the relation account is as shown in Figure C.4.Then,the view relation 0l contains the tuples in Figure C.5. To retrieve the balance of account number A-217 in the view relation 0l,we can write the following query: ?1(A-217”,B)C.3 Datalog 11 in the row “Total.” Such “Where” selections are applied before aggregation, and correspond to selections in an SQL where clause. However, such columns cannot be printed (marked as “Show”). Only columns where the “Total” row specifies either “group by,” or an aggregate function can be printed. Queries are created through a graphical user interface, by first selecting tables. Attributes can then be added to the design grid by dragging and dropping them from the tables. Selection conditions, grouping, and aggregation can then be specified on the attributes in the design grid. Access QBE supports a number of other features too, including queries to modify the database through insertion, deletion, or update. C.3 Datalog Datalog is a nonprocedural query language based on the logic-programming language Prolog. As in the relational calculus, a user describes the information desired without giving a specific procedure for obtaining that information. The syntax of Datalog resembles that of Prolog. However, the meaning of Datalog programs is defined in a purely declarative manner, unlike the more procedural semantics of Prolog, so Datalog simplifies writing simple queries and makes query optimization easier. C.3.1 Basic Structure A Datalog program consists of a set of rules. Before presenting a formal definition of Datalog rules and their formal meaning, we consider examples. Consider a Datalog rule to define a view relation v1 containing account numbers and balances for accounts at the Perryridge branch with a balance of over $700: v1(A, B) :– account(A, “Perryridge”, B), B > 700 Datalog rules define views; the preceding rule uses the relation account, and defines the view relation v1. The symbol :– is read as “if,” and the comma separating the “account(A, “Perryridge”, B)” from “B > 700” is read as “and.” Intuitively, the rule is understood as follows: for all A, B if (A, “Perryridge”, B) ∈ account and B > 700 then (A, B) ∈ v1 Suppose that the relation account is as shown in Figure C.4. Then, the view relation v1 contains the tuples in Figure C.5. To retrieve the balance of account number A-217 in the view relation v1, we can write the following query: ? v1(“A-217”, B)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有