Lesson Plan
Theory
Relational Algebra & Sets
Practice
SQL
SQLite
Self-Directed Learning
Theory
Set Theory
The branch of mathematics that deals
with the formal properties of sets as
units (without regard to the nature of
their individual constituents) and the
expression of other branches of
mathematics in terms of sets
Why This Is Important
A whole branch of mathematics that deals
with collections of items and operations.
SQL is just one of many ways to describe
collections of items and operations.
Learning to think about data as discrete sets
of items opens new possibilities, because you
are given new operations to manipulate sets.
SQL
Structured Query Language
SQL is a language standard
Different databases products have extra
features tacked on to the language
Understand the structure of the language
Everything else is just syntax
SQLite
Free and Open Source relational database LIBRARY
Most SQL products are considered a “RDBMS”
Relational Database Management System
Which means they contain extra functionality
Networking
Backups
Authentication
Etc....
Digression: Keys
Most data has a unique identifier, somewhere
People: Social Security Numbers
Groceries: UPC/Barcodes
Cars: VIN
SQL has a data type to give hints to the
database engine about these unique identifiers
Keys
Typically a table will have a PRIMARY KEY
Often, it is a automatically incremented
integer
Blog post #1
Blog post #2
....
Connecting Tables
(Relations)
Two tables can be related through the use of
FOREIGN KEYS
Customer table has a primary key (customer_id)
Order table has a primary key (order_id) and a
column (customer) that references the customer
table.
The SQL database now knows about this relation.
Foreign Keys &
Referential Integrity
Foreign keys are used to enforce
REFERENTIAL INTEGRITY
You cannot have an order for a customer
that doesn’t exist.
You cannot delete a customer unless you also
delete their orders.
SQLite Example
We will now go through a hands-on exercise
with SQLite and the sample database from
GitHub
A more complete example database can be
found on the Chinook Project:
http://chinookdatabase.codeplex.com/
This is listed in Lesson_04.md of the GitHub
project