tailieunhanh - Joe Celko s SQL for Smarties - Advanced SQL Programming P72

Joe Celko s SQL for Smarties - Advanced SQL Programming P72. In the SQL database community, Joe Celko is a well-known columnist and purveyor of valuable insights. In Joe Celko's SQL for Smarties: Advanced SQL Programming, he picks up where basic SQL training and experience leaves many database professionals and offers tips, techniques, and explanations that help readers extend their capabilities to top-tier SQL programming. Although Celko denies that the book is about database theory, he nevertheless alludes to theory often to buttress his practical points. This title is not for novices, as the author points out. Instead, its intended. | 682 CHAPTER 30 GRAPHS IN SQL The most common way to model a graph in SQL is with an adjacency list model. Each edge of the graph is shown as a pair of nodes in which the ordering matters and then any values associated with that edge are shown in another column. Basic Graph Characteristics The following code is from John Gilson. This code uses an adjacency list model of the graph with nodes in a separate table. This is the most common method for modeling graphs in SQL. CREATE TABLE Nodes node_id INTEGER NOT NULL PRIMARY KEY CREATE TABLE AdjacencyListGraph begin_node_id INTEGER NOT NULL REFERENCES Nodes node_id end_node_id INTEGER NOT NULL REFERENCES Nodes node_id PRIMARY KEY begin_node_id end_node_id CHECK begin_node_id end_node_id It is also possible to load an acyclic directed graph into a nested set model by splitting the nodes. CREATE TABLE NestedSetsGraph node_id INTEGER NOT NULL REFERENCES Nodes node_id lft INTEGER NOT NULL CHECK lft 1 PRIMARY KEY rgt INTEGER NOT NULL UNIQUE CHECK rgt lft UNIQUE node_id lft To split nodes start at the sink nodes and move up the tree. When you come to a node with an indegree greater than one replace it with that many copies of the node under each of its superiors. Continue to do this until you get to the root. The acyclic graph will become a tree but with duplicated node values. There are advantages to this model we will discuss them in Section . All Nodes in the Graph To view all nodes in the graph use the following o Basic Graph Characteristics 683 CREATE VIEW GraphNodes node_id AS SELECT DISTINCT node_id FROM NestedSetsGraph Path Endpoints A path through a graph is a traversal of consecutive nodes along a sequence of edges. Clearly the node at the end of one edge in the sequence must also be the node at the beginning of the next edge in the sequence. The length of the path is the number of edges that are traversed along the path. Path endpoints are the first and last nodes of each path in the .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.