Download OODB and XML

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft Access wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Relational algebra wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

Clusterpoint wikipedia , lookup

PL/SQL wikipedia , lookup

Versant Object Database wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
OODB and XML
Database Management Systems – Fall 2012
CompanyMatthew
LOGO
Moccaro
Outline
1. OODB
2. OODB AND SQL
3. XML
4. XML Queries
Object Databases
Object Databases
Object Databases
A History
• First arrived in the 1980s and 1990s
• Use objects to represent data with a set of
attributes.
• Developed due to certain limitations of the
very popular relational model.
 Let’s take a look at an example of one of
these limitations.
Limitations Example: Part 1
SSN
Name
PhoneN
Child
111-22-3333
Joe Public
516-123-4567 222-33-4444
111-22-3333
Joe Public
516-345-6789 222-33-4444
111-22-3333
Joe Public
516-123-4567 333-44-5555
111-22-3333
Joe Public
516-345-6789 333-44-5555
222-33-4444
Bob Public
212-987-6543 444-55-6666
222-33-4444
Bob Public
212-987-1111
222-33-4444
Bob Public
212-987-6543 555-66-7777
222-33-4444
Bob Public
212-987-1111
555-66-7777
444-55-6666
Limitations Example: Part 2
SSN
Name
PhoneN
Child
111-22-3333
Joe Public
516-123-4567 222-33-4444
111-22-3333
Joe Public
516-345-6789 222-33-4444
111-22-3333
Joe Public
516-123-4567 333-44-5555
111-22-3333
Joe Public
516-345-6789 333-44-5555
222-33-4444
Bob Public
212-987-6543 444-55-6666
222-33-4444
Bob Public
212-987-1111
222-33-4444
Bob Public
212-987-6543 555-66-7777
222-33-4444
Bob Public
212-987-1111
555-66-7777
444-55-6666
Limitations Example: Part 3
Explanation
• There are several ways around this problem,
however, they normally lead to more difficulties.
• More tables, more complex queries.
 Our solution can be an OODB. To help explain
an object database, let’s compare it to something
we are familiar with, the relational model.
Object Vs. Relational: Part 1
Object Database
Relational Database
Contains Classes
Contains Relations
which are:
which are:
Sets of Objects
Sets of Tuples
Object Vs. Relational: Part 2
Object Database
Relational Database
Components of
an object can be
complex types.
Components of a
tuple must be
primitive types.
Sets, Tuples,
Objects…..
Strings, Integers…
Object Vs. Relational: Part 3
Object Database
•
Objects can have
inheritance.
•
Objects can have
methods.
•
Can be all in the
same language.
Relational Database
N/A
OODB
The Conceptual Object Data Model
TEXT
TEXT
• Helps us to understand OODB.
• Let’s take a better look at:
• Objects
• Classes
• Types
The Conceptual Object Data Model
Objects
TEXT
TEXT
• In this model, each object has an individual ID.
• Called an “oid”
• Different from a Primary Key
• Cannot change for an object
• Values
• Can Change
• Can be complex
The Conceptual Object Data Model
Classes
TEXT
TEXT
• Organizes similar objects
• Class called Person contains objects with
information regarding each person.
• Classes Have:
• Type
• Method Signatures
• Extent
The Conceptual Object Data Model
Types
TEXT
• Types could be:
• Basic
• Reference
• Tuple
• Set
• Subtype and Supertype
TEXT
Object-Relational Database
Object Relational Database
 Combination of Object and Relational Databases
•
•
Top Level Classes which contain tuples.
These classes are called “relations.”
 Tuples are “tuple objects.”
•
•
Top level structure is always a tuple.
Can have complex values.
Object Databases
Object Databases and SQL
Object Databases
A History
• First added to SQL in SQL:1999
•
Created with backwards compatibility in mind.
• SQL-92
• Remained in SQL:2003, SQL:2008,
and SQL:2011.
Row Type
A New Type
• To create a tuple type in SQL, we can now use the
row keyword:
CREATE TABLE Person(
Name CHAR(20),
Address ROW(Number INTEGER, STREET CHAR(20), ZIP CHAR(5)))
To insert new values:
INSERT INTO Person(Name, Address)
VALUES (‘John Doe’, ROW(666, ‘Hollow Rd.’, ‘66666’))
Creating Objects
Creating A Type
• To create an object in SQL, we need to go through
a few steps.
1. First we can define a type.
CREATE TYPE StudentType AS(
Address ROW(Number INTEGER, STREET CHAR(20), ZIP CHAR(5)))
Id INTEGER,
Status CHAR(2));
Creating Objects
Creating A Table
2. Next, we can create a new table from our type.
CREATE TABLE Student OF StudentType;
SQL regards the rows of a table declared in this way
as objects.
The book introduces many other new concepts in this
area.
XML
XML
XML
A History
•
XML was first developed in the late 1990s and
came into popularity soon after.
• EXtensible Markup Language
• HTML displays data, XML carries data
• File Extension is .xml

Let’s create a file….
XML Example File
First, we can start by making an XML declaration…..
<?xml version=“1.0” encoding=“UTF-8” ?>
XML Example File
Comments are done as <!-- Comment -->
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
XML Example File
Let’s make a menu. So we’ll declare some menu tags.
This is called the root element.
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
</menu>
All elements must have an open
and close tag. Close tags have a “/”
XML Example File
Now let’s put an entrée section.
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
<entree>
</entree>
</menu>
XML Example File
Let’s add some details. How about a name?
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
<entree>
<name>Sunburnt Chicken</name>
</entree>
</menu>
XML Example File
And a detail about this entrée.
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
<entree>
<name>Sunburnt Chicken</name>
<fatgrams>23</fatgrams>
</entree>
</menu>
XML Example File
Let’s add an entirely new entrée.
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
<entree>
<name>Sunburnt Chicken</name>
<fatgrams>23</fatgrams>
</entree>
<entree>
<name>Gusto Spaghetti</name>
<fatgrams>55</fatgrams>
</entree>
</menu>
XML Example File
Attributes can help make things more clear.
We could do this….
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
<entrée1>
<name>Sunburnt Chicken</name>
<fatgrams>23</fatgrams>
</entrée1>
<entrée2>
<name>Gusto Spaghetti</name>
<fatgrams>55</fatgrams>
</entrée2>
</menu>
XML Example File
But you can also add attributes within a tag.
< tagname something = “value” >
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu>
<entrée id = “1”>
<name>Sunburnt Chicken</name>
<fatgrams>23</fatgrams>
</entrée>
<entrée id = “2”>
<name>Gusto Spaghetti</name>
<fatgrams>55</fatgrams>
</entrée>
</menu>
XML
XML
•
Can be formatted in several ways.
• CSS
• XSLT
• Documents can be validated by:
• XML Schemas
• DTDs
 Let’s take a look at some XML queries….
XML Queries
XML Queries
XML Queries
DTD
XSLT
XML
Schema
XML
XQuery
XPath
XML Query Languages
XPath
XSLT
XQuery
Solutions for XML Queries
XPath
XPath
•
XML Query Language which views XML
documents as trees.
• Things such as comments and elements
are nodes of these trees.
• Allows us to traverse the tree and find a
“path” to what we need.
• Gives us an easy to understand language for
querying XML Documents.
XSLT
XSLT
• XSL Transformation
•
•
•
•
Files usually called stylesheets.
Can be used to query and to format XML
Includes conditional instructions….
More powerful query language which can
utilize parts of XPath.
• Certain queries such as joins can still be
difficult in XSLT.
XQuery
XQuery
• Built by taking the best parts of two other
query languages, XQL and XML-QL.
• Still uses XPath as a syntax for its
expressions.
• More similar to SQL:
FOR (variable declarations)
WHERE (condition)
RETURN (result)
SQL/XML
SQL/XML
• Slowly becoming part of the SQL standard.
• Allows us to work directly with XML
documents from SQL.
• Many vendors such as Oracle, MS SQL
Server, MySQL, and PostgreSQL already
have much functionality built-in.
Summary
1. OODB
Object Databases help us to excel where the relational model may be cumbersome.
2. OODB AND SQL
Allow us to integrate objects into our databases while still utilizing SQL.
3. XML
A highly customizable language which helps us to represent data almost universally.
4. XML Queries
Gives us many different languages to use XML to its full potential.
The End
Thank You!
References:
References:
Wagner, Richard and Richard Mansfield. XML for Dummies
For Dummies. 2003.
Kifer, Michael and Arthur Bernstein, and Philip M. Lewis Database Systems
Boston: Pearson Education, 2006
XML Tutorial. W3 Schools. 2012 Web. Nov. 2012
http://www.w3schools.com/xml/
SQL/XML. Wikipedia. 2012 Web. Nov. 2012
http://en.wikipedia.org/wiki/SQL/XML