Database Management System (DBMS):
Provides
efficient, convenient, and safe
multi-user
storage of and access to massive amounts of persistent
data
Most familiar use: many Web sites rely heavily on DBMS's. (And you will build one!)
Examples: (solicit from class)
Non-Web examples of DBMS's: (solicit from class)
Jane and John both have ID number for bookseller gift certificate (credit) of $200 they got as a wedding gift.
Jane @ her office: orders "Database Systems: The Complete Book" ($75)
prompt user for credit ID;
get credit from database;
if credit >= 75 then
credit := credit - 75;
issue order to mail book;
put new credit into database;
else print "sorry"
John @ his office: orders "A First Course in Database Systems" ($65)
prompt user for credit ID;
get credit from database;
if credit >= 65 then
credit := credit - 65;
issue order to mail book;
put new credit into database;
else print "sorry"
Initial credit = $200
(Example: Student, Campus)
Each relation has a set of attributes (or columns), with a distinct name within its relation.
(Example: label Student, Campus)
Each tuple (or row) in a relation has a value for each attribute.
(Example: some tuples for Student, Campus relations)
Each attribute has a type (or domain).
ID:char(9), name:char(25), GPA:float, age:integer
We'll use atomic (indivisible) types only for now.
Specifying the schema (on paper):
Student(ID,
name, GPA, age)
Student(ID:
char(9), name: char(25), GPA: float, age: integer)
Student(ID, name, GPA, age)
Campus(name, enrollment) <- duplicate use of "name" okay
Apply(ID, Campus) <- "ID" okay, "Campus" not okay
Null values:
Keys: A key for a relation is a set of attributes such that no two tuples can have the same values for all of their key attributes.
http://www.w3.org/XML/It will keep you busy for days. A very short document linked from that site and the course schedule ("XML in 10 points") is required reading.
In HTML, tags denote formatting: <Title>,
<I>, <Table>, etc.
In XML, tags denote meaning of data: <Student>,
<Book_Title>, etc.
XML data can be formatted using CSS (Cascading Style Sheets) or XSL (Extensible Stylesheet Language) to translate XML to HTML.
Example: bookstore data
<?xml version="1.0" standalone="yes"?>
<Bookstore>
<Book ISBN="ISBN-0-13-035300-0" Price="$65" Edition="2nd">
<Title>A First Course in Database Systems</Title>
<Authors>
<Author>
<First_Name>Jeffrey</First_Name>
<Last_Name>Ullman</Last_Name>
</Author>
<Author>
<First_Name>Jennifer</First_Name>
<Last_Name>Widom</Last_Name>
</Author>
</Authors>
</Book>
<Book ISBN="ISBN-0-13-031995-3" Price="$75">
<Title>Database Systems: The Complete Book</Title>
<Authors>
<Author>
<First_Name>Hector</First_Name>
<Last_Name>Garcia-Molina</Last_Name>
</Author>
<Author>
<First_Name>Jeffrey</First_Name>
<Last_Name>Ullman</Last_Name>
</Author>
<Author>
<First_Name>Jennifer</First_Name>
<Last_Name>Widom</Last_Name>
</Author>
</Authors>
<Remark>
Amazon.com says: Buy this book bundled with "A First Course,"
it's a great deal!
</Remark>
</Book>
</Bookstore>
A well-formed XML document can contain regular data (as above) or very
irregular data.
A DTD is a grammar that describes the legal attributes of tagged elements and the legal ordering and nesting of the elements.
<!ELEMENT Bookstore (Book | Magazine)*>
<!ELEMENT Book (Title, Authors, Remark?)>
<!ATTLIST Book ISBN CDATA #REQUIRED
Price CDATA #REQUIRED
Edition CDATA #IMPLIED>
<!ELEMENT Magazine (Title)>
<!ATTLIST Magazine Month CDATA #REQUIRED Year CDATA #REQUIRED>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Authors (Author+)>
<!ELEMENT Remark (#PCDATA)>
<!ELEMENT Author (First_Name, Last_Name)>
<!ELEMENT First_Name (#PCDATA)>
<!ELEMENT Last_Name (#PCDATA)>
The DTD is specified at the top of the document or in a separate file
referenced at the top of the document. In both cases use
standalone="no".
Question: What are the benefits of using a DTD?
Question: What are the benefits of not using a DTD?
ID
attribute to an
element, then point to that element with a special IDREF
or
IDREFS attribute in another element.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE Bookstore SYSTEM "bookstore.dtd">
<Bookstore>
<Book ISBN="ISBN-0-13-035300-0" Price="$65" Edition="2nd" Authors="JU JW">
<Title>A First Course in Database Systems</Title>
</Book>
<Book ISBN="ISBN-0-13-031995-3" Price="$75" Authors="HG JU JW">
<Title>Database Systems: The Complete Book</Title>
<Remark>
Amazon.com says: Buy this book bundled with
<BookRef book="ISBN-0-13-035300-0" />,
It's a great deal!
</Remark>
</Book>
<Author Ident="HG">
<First_Name>Hector</First_Name>
<Last_Name>Garcia-Molina</Last_Name>
</Author>
<Author Ident="JU">
<First_Name>Jeffrey</First_Name>
<Last_Name>Ullman</Last_Name>
</Author>
<Author Ident="JW">
<First_Name>Jennifer</First_Name>
<Last_Name>Widom</Last_Name>
</Author>
</Bookstore>
DTD for this data:
<!ELEMENT Bookstore (Book*, Author*)>
<!ELEMENT Book (Title, Remark?)>
<!ATTLIST Book ISBN ID #REQUIRED
Price CDATA #REQUIRED
Edition CDATA #IMPLIED
Authors IDREFS #REQUIRED>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Remark (#PCDATA | BookRef)*>
<!ELEMENT BookRef EMPTY>
<!ATTLIST BookRef book IDREF #REQUIRED>
<!ELEMENT Author (First_Name, Last_Name)>
<!ATTLIST Author Ident ID #REQUIRED>
<!ELEMENT First_Name (#PCDATA)>
<!ELEMENT Last_Name (#PCDATA)>
#PCDATA is only for
element content, CDATA is
only for attribute types, you cannot use them interchangeably, and
there are no keywords PCDATA or #CDATA.
Both
CDATA and #PCDATA
essentially specify text where the
special characters "<", ">", and "&" have to be
escaped as
"<", ">" and "&" respectively.
CDATA
for string-valued
attributes, use #PCDATA for elements
containing text. If you
want an element to contain a mixture of text and other elements, do so
by specifying the element types along with #PCDATA
in a
0-or-more list, e.g., (#PCDATA | Author |
Editor)*.