Databases Reference
In-Depth Information
Chapter 12
G r o u p a n d U n g r o u p V i e w s
Updating groups
Don't need no loops
—Anon.: Where Bugs Go
I turn now to the question of updating through the relational grouping and ungrouping operators
(GROUP and UNGROUP, in Tutorial D ). Since you might not be familiar with those operators,
I'll begin with a brief tutorial.
THE GROUP AND UNGROUP OPERATORS
Consider the relations shown in Fig. 12.1, which we can take to be the current values of two
relvars called SP and SPQ, respectively. Of course, relvar SP is just the shipments relvar from
our usual suppliers-and-parts database.
SP SPQ
┌─────┬─────┬─────┐ ┌─────┬───────────────┐
│ SNO │ PNO │ QTY │ │ SNO │ PQ │
├═════┼═════┼─────┤ ├═════┼───────────────┤
│ S1 │ P1 │ 300 │ │ │ ┌─────┬─────┐ │
│ S1 │ P2 │ 200 │ │ S1 │ │ PNO │ QTY │ │
│ S2 │ P1 │ 300 │ │ │ ├═════┼─────┤ │
└─────┴─────┴─────┘ │ │ │ P1 │ 300 │ │
│ │ │ P2 │ 200 │ │
│ │ └─────┴─────┘ │
│ │ ┌─────┬─────┐ │
│ S2 │ │ PNO │ QTY │ │
│ │ ├═════┼─────┤ │
│ │ │ P1 │ 300 │ │
│ │ └─────┴─────┘ │
└─────┴───────────────┘
Fig. 12.1: Relvars SP and SPQ—sample values
Now, I hope it's at least intuitively obvious that we have information equivalence here once
again 1 (certainly the relations shown in the figure both represent the exact same information).
1 But see the footnote at the very end of this section.
Search WWH ::




Custom Search