Throughout the chapter, I will use three scenarios: Employee Organizational Chart (tree, hierarchy); Bill Of Materials, or BOM (DAG); and Road System (undirected cyclic graph). Note what distinguishes a (directed) tree from a DAG. All trees are DAGs, but not all DAGs are trees. In a tree, an item can have at most one parent; in some management hierarchies, an employee can have more than one manager.

Employee Organizational Chart

The employee organizational chart that I will use is depicted graphically in Figure 12-2.

Employee organizational chart

Figure 12-2. Employee organizational chart

To create the Employees table and populate it with sample data, run the code in ...

Get Inside Microsoft® SQL Server® 2008: T-SQL Querying now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.