Chapter 26. XQuery for SQL Users
This chapter is designed to provide some background material for readers who are already using SQL and relational databases. It compares SQL and XQuery at both the data model and syntax levels. It also provides pointers for using SQL and XQuery together, and describes the role of SQL/XML.
Relational Versus XML Data Models
As you may know, relational databases represent data in terms of tables, rows, and columns. Some XML documents, such as our product catalog document, map fairly cleanly onto a relational model. Example 26-1 shows catalog2.xml, a slightly simplified version of the product catalog document used throughout this book.
Example 26-1. Product catalog document (catalog2.xml)
<catalog><productdept="WMN"><number>557</number><name>Fleece Pullover</name></product><productdept="ACC"><number>563</number><name>Floppy Sun Hat</name></product><productdept="ACC"><number>443</number><name>Deluxe Travel Bag</name></product><productdept="MEN"><number>784</number><name>Cotton Dress Shirt</name><desc>Our favorite shirt!</desc></product></catalog>
Because the product catalog document is relatively uniform and does not contain any repeating relationships between objects, the product catalog can be represented as a single relational table, shown in Table 26-1. Each product is a row, and each possible property of the product is a column.
| number | dept | name | desc |
|---|---|---|---|
| 557 | WMN | Fleece Pullover | |
| 563 | ACC | Floppy Sun Hat | |
| 443 | ACC | Deluxe Travel ... |
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