SQL: a language for forming database queries
- Structured Query Language, pronounced "S-Q-L" or "sequel"
- has become the lingua franca of database management products (lingua franca:
a common language used by speakers of different languages)
- SQL contains a few specific commands for filtering information contained
in a database, yet queries are somewhat English-like in appearance
- SELECT command specifies which fields to display from matching records
- FROM command specfies which database table to search
- WHERE command specifies search criteria to filter records from the
database
- think of database as mathematical set of records and the WHERE command
defines subsets whose intersections (AND) and unions (OR) determine matches
- Some SQL examples for database table StudentList that has fields called FirstName, LastName, Age, Credits (and more):
- SELECT FirstName FROM StudentList WHERE LastName = "Jones"
- SELECT FirstName, LastName FROM StudentList WHERE (Age > 20 AND Credits < 12)
Relational databases
- A database may consist of many related tables.
- The example in the textbook is a student database for a university.
- There is a table containing transcript information, another table containing
financial aid information, another table containing class rosters.
- Some information is required by all three: student name, ID, class rank,
and major.
- If this common info is replicated in all three, then any change to it
(say, student changes major) requires all three tables to be updated.
- In complex systems, this becomes very error-prone.
- Solution: place common information into a separate table, where other
tables can point to it. Change only needs to be made in one place!
- Since tables point to each other, we say they are related and call it
a relational database.
- In this example, "pointing to" is accomplished by storing the student's
ID in all the tables.
Microsoft Access as illustration
- Access is the DBMS (DataBase Management System) part of Microsoft Office
suite.
- Widely used for "small" databases and easy to use
- Comes with sample databases.
- Illustrate with the Northwind Traders sample.
- some terminology:
- the entire database is stored in one file, identified by ".mdb"
filename extension
- the database consists of 7 different types of objects:
- a table is one grid of information. Each row is a record,
each column is a field.
- a query is a stored query specification (e.g. an SQL command).
- a form is a nicely structured data entry form so you can enter
data more easily (instead of directly into the grid)
- a report is a nicely structured data display form so you can view
data more easily
- a page is a web page which can be generated from database
contents
- a macro is a stored command sequence, so you can easily automate
repetitious tasks
- a module is a computer program you can write using Visual Basic
language to perform special processing.
Here is a view of
the Northwind database, with the list of tables shown. You can view a
table by double-clicking on its name or icon.
You can get an idea of the nature of Northwind just by reading the names of
the various tables. This is a relational database, and the relationships
are shown in this illustration. The list of identifiers in each box is the
list of fields in that table, and the lines represent relationships.
Databases and privacy
The textbook briefly describes a plethora of database-related privacy
horror-stores, most caused by criminals creating or stealing an "identity" or
mistakes made by credit bureaus.
What are some of the privacy concerns related with databases?
Did you know that the U.S. Constitution does not explicitly address the right
to privacy?
Do you feel the greater privacy threat is government, or the private sector?
Sometimes it is possible to uniquely identify you and reveal information
about you by combining different pieces of information gleaned from multiple
unrelated databases. This is called record matching.
Geneologists have long depended on this technique to learn about their
ancestors. The government depends on this technique to identify potential terrorists.
Sometimes even summaries of anonymous survey results can uniquely identify
you. For example, my previous university compiles and publishes an annual
report based on faculty survey information. One of the summary categories
is average salary by age group (20-29, 30-39, ..., 70-above). There is one
professor in the "70 - above" age group. The survey is not anonymous for
him.