Appendix: Glossary of Database Terms
A SQL script is a plain text file (usually ending in .sql) that contains one or more SQL statements. Instead of typing commands one by one in the terminal, you write them all in a file and run the whole thing in one go.
This is extremely useful for:
Throughout this course we will use a sample database: a library of 100 books by 24 authors — ranging from J.K. Rowling and Tolkien to Agatha Christie, Toni Morrison, and Kazuo Ishiguro. Some authors have a single book, others have a whole series.
The database has two tables:
authors (id, first_name, last_name, nationality, birth_year)
books (id, title, published_year, genre, author_id)
The script books_library.sql creates both tables, then inserts all the data. You can download it (and the ready-made .db file) from the course materials.
In SQLite, a database is just a file. You create one simply by opening it:
sqlite3 books_library.db
If the file does not exist yet, SQLite creates it automatically. You will see the sqlite> prompt. Type .quit to exit — the (empty) file now exists on disk.
There are two ways to run a .sql file.
Option A — redirect the file on the command line (recommended)
Run this from your terminal (not from inside sqlite3):
sqlite3 books_library.db < books_library.sql
SQLite reads every statement in the file and executes them all. If the database file does not exist it is created first.
Option B — use .read inside the SQLite shell
If you are already inside the sqlite3 shell, use the .read dot command:
sqlite3 books_library.db
.read books_library.sql
Still inside the shell, run a quick check:
.tables
SELECT COUNT(*) FROM authors;
SELECT COUNT(*) FROM books;
You should see 24 authors and 100 books. To see a sample:
.headers on
.mode column
SELECT b.title, a.first_name || ' ' || a.last_name AS author
FROM books b
JOIN authors a ON a.id = b.author_id
LIMIT 10;
<aside> 💡
Add a YouTube video here demonstrating loading a SQL script with the SQLite CLI. This video he downloads a sql script from the internet, in keeping with our authors books theme you can get the sql script right here:
https://www.youtube.com/watch?v=V40VYF1hHlM
</aside>
DBeaver can run a SQL script just as easily. This is often more comfortable because you can see results in a table and spot errors more clearly.
If you do not have a .db file yet, you need to create one first.
C:\\Users\\yourname\\projects\\books_library.db/Users/yourname/projects/books_library.dbThe empty database file is now created and connected.
A blank SQL editor tab will open.
Option A — Open the script file directly
books_library.sql and open it.Option B — Paste the script
books_library.sql in any text editor and copy all the content.Important: Use Execute Script (▶▶), not Execute Statement (▶). "Execute Statement" only runs the single statement under your cursor; "Execute Script" runs everything.
In the Database Navigator, expand your connection → Tables. You should see authors and books. Double-click either table to browse the data, or run a query:
SELECT b.title, b.published_year, a.first_name || ' ' || a.last_name AS author
FROM books b
JOIN authors a ON a.id = b.author_id
ORDER BY b.published_year DESC
LIMIT 10;
<aside> 💡
Add a YouTube video here demonstrating running a SQL script in DBeaver.
</aside>
.read in the CLI, make sure the path to the .sql file is correct relative to where you launched sqlite3.books_library.sql script uses DROP TABLE IF EXISTS at the top, so it is safe to run more than once — it will reset the database cleanly..db file, the CLI may refuse to open it at the same time (and vice versa). Close one before using the other.The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

Built with ❤️ by the HackYourFuture community · Thank you, contributors
Found a mistake or have a suggestion? Let us know in the feedback form.