Dates with Databases: v.1
I love data and databases. SQL is sexy in my book. I think in relations, joins, and unions. So, what have I decided to do in my spare time? Take a Stanford MOOC with a friend called Introduction to Databases. Here is my attempt to summarize and discuss what I’ve learned each week. Onward!
Week 1: Introduction to Relational DB’s and XML
TERMS
Compositionality: The ability to run a query on a previous query
DML (Data Manipulation Language): A Query language that also includes the ability to modify data
DTD (Document Type Descriptors): A language or “grammar” that specifies what elements and attributes an XML document can contain, how they can nested, and other details like ordering and number of occurrences. DTD’s allow for ID’s and IDREFS which are special attributes that operate as pointers in a document. DTD specifications can go at the top of the XML file or in a separate document.
The Relational Model: Simple model with efficient implementations that can be queried using high level languages. relations == tables tuples == rows attributes == columns key == attribute of relation (unique) domain == data type (atomic or structured) instance == table contents
Query: A question(s) you pose to a DB
XML (Extensible Markup Language): A standard for data representation and exchange AND a data model. It was initially designed to exchange data on the internet and has a streaming format or standard. Its three main components are tagged elements, attributes, and text.
XSD (XML Schema Descriptions): Much like DTD’s, but XSD’s are written in XML. XSD’s are always placed in a separate file. Four features in XSD’s that are NOT in DTD’s: 1) Typed values (string, integer, etc.) 2) Key declarations 3) References 4) Current constraints
QUESTIONS
Why use keys?
1) You can use them to identify specific tuples
2) DB systems build index systems to find tuples efficiently using keys
3) They can be used to point to specific tuples
What does it mean that DB’s support ad-hoc queries?
This means that you can pose queries to DB’s that you do not need to think of in advance.
What does “closure of the language mean”?
This means that you get back the same type of object that you query.
What are the main differences between the relational data model and the XML data model?
RelationalXMLStructuretableshierarchical, tree, graphSchemafixed in advanceflexible “self-describing”Queries simple less so Ordering none implied Implementationnativeadd-on
What are some ways to show parsed XML?
Through the DOM (interface that traverses the tree implied by XML) or SAX ( a stream model for XML).
What are the basic structural requirements of well-formed XML?
That there is a single root element, tags are matched with proper nesting, and that there are unique attributes within each element.
What is valid XML?
It adheres to the requirements of well-formed XML, but also to content specific specifications. DTD’s and XSD’s are two examples of languages for those specifications.
What are the benefits of well-formed XML (loosely-typed data) vs. valid XML? (strongly-typed data)
The latter enables programs and processes using the XML to expect a specific structure, and it serves as documentation to communicate the structure of the data to other parties involved in the data exchange. The formed allows for more flexibility, and will run into fewer errors especially when the data involved is highly irregular.
HOW TO RUN FILES
To validate XML data with DTD in same file
xmllint --valid --noout DataFileWithDTD.xml
To validate XML data with DTD in separate file
xmllint --dtdvalid DTD.dtd --noout DataFileWithoutDTD.xml
To validate XML data against separate XSD
xmllint --schema XMLSchemaFile.xsd --noout DataFile.xml
Online services to validate XML: the W3C Markup Validation Service for DTDs, and the XML for ASP.NET Schema Validator for XML Schema.
NOTES
- Be aware of how you treat NULL in your queries.
- Relational algebra is a “formal” language whereas SQL is an “actual” or “implemented” language, although SQL has its foundation in relational algebra. - XML looks a lot like HTML, but the main difference is that HTML tags describe the format of the data whereas XML tags refer to the content.
- When you want to format data in an XML document you can used a rule-based language (like CSS or XSL) to translate it into HTML.
- All attributes in DTD’s are stringed - Note the similarity with regex in DTD
Syntax Meaning ? 0 or 1 * 0 or more + 1 or more















