A Brief Guide to Databases

From GMOD
Revision as of 21:31, 6 September 2012 by Girlwithglasses (Talk | contribs)

Jump to: navigation, search

A database provides infrastructure for storing, managing, and retrieving information.


Tables, Records, and Attributes

Databases store information in tables. A database usually has multiple tables containing data on different types of things.

Each table in the database can be broken down into rows and columns, like a spreadsheet.

Rows, or records, represent one instance of the type of item described in the table.

Columns, or attributes, are the aspects of the item that we are collecting information on.

Example

Here's an example of a table in a database containing information about some books. Each record represents a book, and the attributes that we are collecting information on are the ISBN, the title, the author, the publication date, and whether a Kindle version is available.

book
ISBN Title Author Publication date Kindle version
9400707495 Mouse as a Model Organism: From Animals to Cells Cord Brakebusch and Taina Pihlajaniemi Apr 2011 1
0199567581 Dragonflies and Damselflies: Model Organisms for Ecological and Evolutionary Research Alex Córdoba-Aguilar Dec 2009 1
0195179927 Mathematical Models in Biology (Classics in Applied Mathematics) Leah Edelstein-Keshet Feb 2005 0
0879698659 Evolutionary Ecology of Social and Sexual Systems: Crustaceans As Model Organisms J. Emmett Duffy and Martin Thiel Sep 2007 1
0879698721 Emerging Model Organisms: A Laboratory Manual, Volume 2 Cold Spring Harbor Laboratory Press Apr 2011 0
0805074589 Emerging Model Organisms: A Laboratory Manual, Volume 1 Cold Spring Harbor Laboratory Press Nov 2008 0
0898715547 A Feeling for the Organism, 10th Aniversary Edition: The Life and Work of Barbara McClintock Evelyn Fox Keller Feb 1984 0


Keys

In a database table, certain attributes (columns) are keys. Keys are used to identify records (rows) and link records together.

A primary key uniquely identifies a record in a database table; the attribute to be the primary key would usually be decided when the database schema is being designed, rather than waiting until after the database has been populated. Some database tables contain more than attribute that can uniquely identify a record. These extra unique keys are alternate keys.

In a relational database, tables are linked together by using the primary key from one table in a related table. The primary key then becomes a foreign key.


Example

Looking at our previous example of the book database, the ISBN is the primary key in this database table. The title could be used as an alternate key, but given how common some book titles are, it would not be a good long term strategy.

book
ISBN Title Author Publication date Kindle version
9400707495 Mouse as a Model Organism: From Animals to Cells Cord Brakebusch and Taina Pihlajaniemi Apr 2011 1
0879698659 Evolutionary Ecology of Social and Sexual Systems: Crustaceans As Model Organisms J. Emmett Duffy and Martin Thiel Sep 2007 1
0879698721 Emerging Model Organisms: A Laboratory Manual, Volume 2 Cold Spring Harbor Laboratory Press Apr 2011 0
0805074589 Emerging Model Organisms: A Laboratory Manual, Volume 1 Cold Spring Harbor Laboratory Press Nov 2008 0
0898715547 A Feeling for the Organism, 10th Aniversary Edition: The Life and Work of Barbara McClintock Evelyn Fox Keller Feb 1984 0


If we now imagine a second table with book prices in it:

price
ISBN Format Price ($)
9400707495 Hardback 189.00
9400707495 Ebook 151.20
0879698659 Hardback 59.99
0879698659 Paperback 14.99
0879698659 Ebook 34.99
0879698721 Hardback 234.00
0879698721 Paperback 134.00
0805074589 Hardback 234.00
0805074589 Paperback 129.00
0898715547 Hardback 64.99

This table has no primary keys, and the ISBN is acting as a foreign key.