SQL is a query language for relational databases developed in 1974 that operates on tables using statements like SELECT, INSERT, and UPDATE. XQuery is a query language for XML data developed in 2007 that operates on hierarchies and supports XPath. While both are query languages, SQL works with relational databases and XQuery works with XML data collections stored in databases or elsewhere.
2. What is SQL?
●
Structured Query Language
●
Works with RDBMS
●
Operates on tables
●
Developed in 1974 by IBM
3. What is SQL?
My_table
Example: field1 field2 field3
test N NULL
INSERT INTO My_table
(field1, field2, field3)
VALUES
('test', 'N', NULL);
UPDATE My_table
SET field1 = 'updated value'
WHERE field2 = 'N';
4. What is XQuery?
●
Query language
●
Works with XML data collections
●
Operates on hierarchies
●
W3C recommendation in 2007
5. What is XQuery?
Example (applied to book.xml):
for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title
for $x in doc("books.xml")/bookstore/book
return
if ($x/@category="CHILDREN")
then <child>{data($x/title)}</child>
else <adult>{data($x/title)}</adult>
6. More about XQuery
●
Supported by most RDBMS
●
Supports XPath
●
Not yet an ISO/ANSI standard (like
SQL)
●
Currently a read-only language
7. More about XQuery
●
Immature, unknown, lacking dev.
tools and communities
●
Open-source implementations
●
Not as efficient as SQL (for now)