Databases using SQL

We use DB Browser for SQLite and the Alzheimer’s Disease Neuroimaging Initiative Teaching dataset throughout this lesson. See Setup for instructions on how to download the data, and also how to install DB Browser for SQLite.

Motivation

To start, let’s orient ourselves in our project workflow. Previously, we used Excel and OpenRefine to go from messy, human created data to cleaned, computer-readable data. Now we’re going to move to the next piece of the data workflow, using the computer to read in our data, and then use it for analysis and visualization.

What is SQL?

SQL stands for Structured Query Language. SQL allows us to interact with relational databases through queries. These queries can allow you to perform a number of actions such as: insert, update and delete information in a database.

Dataset Description

The data we will be using come from a longitudinal study of Alzheimer’s disease called the Alzheimer’s Disease Neuroimaging Initiative (ADNI). ADNI began in 2004 and includes data gathered by investigators at 59 research centers across North America. Participants in the study are older adults along the full spectrum of cognitive health, from Normal Control (NC) through Early and Late Mild Cognitive Impairment (EMCI/LMCI) and Alzheimer’s dementia (AD). The dataset includes individual-level demographics, such as age, sex, and education; measures of cognitive performance, such as scores on tests of memory and attention; and results of biomarker assessment, including genetic markers of risk, brain volumes, and amounts of AD proteins in brain and cerebrospinal fluid (CSF).

This is a real dataset that has been used in over 1700 publications. We’ve simplified it for the workshop, removing or altering some information about individual patients in the process. ADNI is a fairly open dataset, meaning that many researchers who are not part of the original team have access to the data. However, because these data are about real patients, some extra permissions are required for each new use of the data. If you’re interested in taking the work we do today further with the full dataset, you should submit a separate data request to ADNI.

Questions

First, let’s download and look at some of the cleaned spreadsheets from the ADNI Teaching dataset.
We’ll need the following files:

Challenge

Goals

In order to answer the questions described above, we’ll need to do the following basic data operations:

In addition, we don’t want to do this manually! Instead of searching for the right pieces of data ourselves, or clicking between spreadsheets, or manually sorting columns, we want to make the computer do the work.

In particular, we want to use a tool where it’s easy to repeat our analysis in case our data changes. We also want to do all this searching without actually modifying our source data.

Putting our data into a relational database and using SQL will help us achieve these goals.

Definition: Relational Database

A relational database stores data in relations made up of records with fields. The relations are usually represented as tables; each record is usually shown as a row, and the fields as columns. In most cases, each record will have a unique identifier, called a key, which is stored as one of its fields. Records may also contain keys that refer to records in other tables, which enables us to combine information from two or more sources.

Databases

Why use relational databases

Using a relational database serves several purposes.