Joe Celko's SQL for Smarties: Advanced SQL Programming, Third Edition

Chapter 28: Trees and Hierarchies in SQL

Overview

I have a separate book ( Joe Celko's Trees and Hierarchies in SQL for Smarties, 2004) devoted to this topic in great detail, so this chapter will be a very quick discussion of the three major approaches to modeling trees and hierarchies in SQL.

A tree is a special kind of directed graph. Graphs are data structures that are made up of nodes (usually shown as boxes) connected by edges (usually shown as lines with arrowheads). Each edge represents a one-way relationship between the two nodes it connects. In an organizational chart, the nodes are positions that can be filled by employees, and each edge is the "reports to" relationship. In a parts explosion (also called a bill of materials), the nodes are assembly units that eventually resolve down to individual parts from inventory, and each edge is the "is made of" relationship.

The top of the tree is called the root. In an organizational chart, it is the highest authority; in a parts explosion, it is the final assembly. The number of edges coming out of the node is its outdegree, and the number of edges entering it is its indegree. A binary tree is one in which a parent can have at most two children; more generally, an nary tree is one in which a node can have at most outdegree n.

The nodes of the tree that have...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Fieldbus Products
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.