Skip to Content
SQL and Relational Theory, 2nd Edition
book

SQL and Relational Theory, 2nd Edition

by C.J. Date
December 2011
Intermediate to advanced
444 pages
15h 10m
English
O'Reilly Media, Inc.
Content preview from SQL and Relational Theory, 2nd Edition

A NOTE ON RECURSION

Consider the following edited extract from Exercise 5.16 in Chapter 5:

The well known bill of materials application involves a relvar—PP, say—showing which parts contain which parts as immediate components. Of course, immediate components are themselves parts, and they can have further immediate components of their own.

Figure 7-5 below shows (a) a sample value for that relvar PP and (b) the corresponding transitive closure TC.[108] The predicates are as follows:

  • PP: Part PX contains part PY as an immediate component.

  • TC: Part PX contains part PY as a component at some level (not necessarily immediate).

Relvars PP and TC (sample values)

Figure 7-5. Relvars PP and TC (sample values)

Given a (relation) value pp for relvar PP, the relation tc that’s the transitive closure of pp can be defined as follows:

Definition: The pair (px,py) appears in tc if and only if:

  1. It appears in pp, or

  2. There exists some pz such that the pair (px,pz) appears in pp and the pair (pz,py) appears in tc.

In other words, if we think of pp as representing a directed graph, with a node for each part and an arc from each node to each corresponding immediate component node, then (px,py) appears in the transitive closure if and only if there’s a path in that graph from node px to node py. Observe that the definition involves a recursive reference to relation tc.

Aside: In practice relvar PP would probably have a QTY attribute as well (showing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

SQL and Relational Theory, 3rd Edition

SQL and Relational Theory, 3rd Edition

C.J. Date
SQL in a Nutshell, 4th Edition

SQL in a Nutshell, 4th Edition

Kevin Kline, Regina O. Obe, Leo S. Hsu

Publisher Resources

ISBN: 9781449319724Errata Page