Joe Celko's Trees and Hierarchies in SQL for Smarties

1st Edition

Print ISBN: 9781558609204
eBook ISBN: 9780080491691
Imprint: Morgan Kaufmann
Published Date: 7th May 2004
Page Count: 240
35.95 + applicable tax
28.99 + applicable tax
46.95 + applicable tax
Compatible Not compatible
VitalSource PC, Mac, iPhone & iPad Amazon Kindle eReader
ePub & PDF Apple & PC desktop. Mobile devices (Apple & Android) Amazon Kindle eReader
Mobi Amazon Kindle eReader Anything else

Institutional Access


Joe Celko's Trees and Hierarchies in SQL is an intermediate to advanced-level practitioner’s guide to mastering the two most challenging aspects of developing database applications in SQL. In this book, Celko illustrates several major approaches to representing trees and hierarchies and related topics that should be of interest to the working database programmer. These topics include hierarchical encoding schemes, graphs, IMS, binary trees, and more. This book covers SQL-92 and SQL:1999.

Key Features

· Includes graph theory and programming techniques. · Running examples throughout the book help illustrate and tie concepts together. · Loads of code, available for download from


database application developers (from enterprise-level application builders to small business developers)

Table of Contents

1 Graphs, Trees and Hierarchies 1.1 Modeling a Graph in a Program 1.1.1 Adjacency Lists for Graphs 1.1.2 Adjacency Arrays for Graphs 1.1.3 Finding a path in a General Graphs in SQL 1.2 Defining Tree and Hierarchies 1.2.1 Trees 1.2.2 Properties of Hierarchies 1.2.3 Types of Hierarchies 1.3 Note on Recursion

2 Adjacency List Model 2.1 The Simple Adjacency List Model 2.2 The Simple Adjacency List Model is not normalized. 2.2.1 UPDATE Anomalies 2.2.2 INSERT Anomalies 2.2.3 DELETE Anomalies 2.2.4 Structural Anomalies 2.3 Fixing the Adjacency List Model 2.3.1 Concerning the Use of NULLs 2.4 Navigation in Adjacency List Model 2.4.1 Cursors and Procedural Code 2.4.2 Self-joins 2.5 Inserting Nodes in the Adjacency List Model 2.6 Deleting Nodes in the Adjacency List Model 2.6.1 Deleting an Entire Subtree 2.6.2 Promoting a Subordinate after Deletion 2.6.3 Promoting an Entire Subtree after Deletion 2.7 Leveled Adjacency List Model 2.7.1 Numbering the levels 2.7.2 Aggregation in the Hierarchy

3 Path Enumeration Models 3.1 Finding the Depth of the Tree 3.2 Searching for Subordinates 3.3 Searching for Superiors 3.4 Deleting a Subtree 3.5 Deleting a Single Node 3.6 Inserting a New Node 3.7 Splitting up a Path String 3.8 The Edge Enumeration Model 3.9 XPath and XML

4 Nested Set Model of Hierarchies 4.1 Finding Root and Leaf Nodes 4.2


No. of pages:
© Morgan Kaufmann 2004
Morgan Kaufmann
eBook ISBN:
Paperback ISBN:


"I want to say clearly that I think the subject of this proposed book is one for which there will be considerable demand...the topic is poorly understood in general and a good book on the subject will be helpful to the SQL community at large. This book should be of great interest to real-world application programmers...I think that this book would be used on a day-to-day basis (rather than languish on a shelf until some special problem arose)." -Jim Melton, author of SQL:1999.