Summary and Setup
This Library Carpentry lesson introduces librarians to relational database management system using SQLite. At the conclusion of the lesson you will: understand what SQLite does; use SQLite to summarise and link data.
Software Requirements
DB Browser for SQLite
You will need to install DB Browser for SQLite to complete these lessons. DB Browser for SQLite provides a graphical user interface for connecting to and interacting with a SQLite database. This application bundles SQLite, so you won’t need to install SQLite separately.
Note: on Windows, the PortableApp download is recommended as the regular version may take a long time to install on certain systems.
Download the data
To import data, you’ll need to open DB Browser for SQLite and download a zip file containing the data files for this tutorial.
- Download the data files doaj-article-sample.zip from Zenodo.
- Open the zip file with the zip utility on your machine and save the folder and files to a location where you can easily find them. For example, your Desktop.
- Contained in the zip file are two files, doaj-article-sample.db and doaj-article-sample.db.sql. You can either open the database file (less steps) or import the SQL file (more steps).
Open the database file
- Open DB Browser for SQLite.
- Choose “File” > “Open Database” from the menu bar at the top of your screen.
- Navigate to where you saved the doaj-article-sample folder and/or files. For example, your Desktop.
- Select “doaj-article-sample.db”.
Import the SQL file
- Open DB Browser for SQLite.
- Choose “File” > “Import” > “Database” from SQL file from the menu bar at the top of your screen.
- Navigate to where you saved the doaj-article-sample folder and/or files. For example, your Desktop.
- Select “doaj-article-sample.db.sql”.
- You will be prompted to “Save As” (i.e. this is the name of the database).
- Type “doaj-article-sample” in the “Save as” box.
- Make sure that “SQLite database files” is selected in the drop down and that you save the database to a location where you can easily find it, again, like your Desktop.
- Click “Save”.
- You should see an “Executing SQL…” prompt and an “Import completed.” prompt when finished.
- Click “OK”.
- You will see one more prompt which says, “Do you want to save the changes made to the database file…”.
- Click “Save”.
Alternatives: SQLite and SqliteOnline
SQLite
This step is optional. If you are completing the tutorial with DB Browser for SQLite, you won’t need to install SQLite separately. If you would like to run SQLite commands directly on the command line, you may need to install SQLite separately.
Linux and Mac OS x
SQLite command line tools come preinstalled on Linux and Mac OS x.
In order to check they are available type
sqlite3 --version
at the terminal command line. If this
text displays, “Command ‘sqlite3’ not found, but can be installed with:
sudo apt install sqlite3,” it means sqllite3 is not installed on the
machine. To install sqlite3, type sudo apt install sqlite3
.
To exit type exit
.
Windows
On Windows download the Windows
Installer. Copy the file to a directory and open the directory using
the windows command line. Type sqlite3
.
For a more detailed explanation see this tutorial.
SqliteOnline
This step is optional. If you are completing the tutorial with DB Browser for SQLite, you won’t need to use SqliteOnline separately. If you are experiencing trouble with DB Browser for SQLite and/or SQLite or if you would like to run SQL commands online via a browser (nothing to install), then visit https://sqliteonline.com/.
Open the database file in SqliteOnline
- Choose “File” > “Open DB” from the SqliteOnline menu bar.
- Navigate to where you saved the doaj-article-sample folder and/or files. For example, your Desktop.
- Select “doaj-article-sample.db”.
Open the SQL file in SqliteOnline
- Choose “File >”Text-SQL” > “Open SQL” from the SqliteOnline menu bar.
- Navigate to where you saved the doaj-article-sample folder and/or files. For example, your Desktop.
- Select “doaj-article-sample.db.sql”.
- You should see the SQL in a text box below the home icon.
- Click the “Run” button in the SqliteOnline menu bar.