Skip to content
AgileLogics

Programming glossary

Database

A system for storing data so it survives after a program stops, and can be reliably searched and updated.

Data that outlives your program

Variables only last as long as the program that holds them. Close the app or restart the server, and everything in memory is gone. Databases exist so that user accounts, orders, blog posts, and scores survive restarts and can be shared among many users at once. They also do the hard work of searching quickly through millions of records and keeping data consistent when two people update it simultaneously.

You could save data to a plain text file, and small scripts often do. But a file gives you no fast lookups, no protection against two writers clashing, and no easy way to ask questions like "which customers ordered last week?" A database management system (DBMS) handles all of that.

Querying with SQL

Relational databases such as MySQL, PostgreSQL, and SQLite store data in tables of rows and columns, and you talk to them in SQL. This example uses SQLite syntax:

CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, city TEXT);

INSERT INTO users (name, city) VALUES ('Amina', 'Lahore'), ('Leo', 'Berlin');

SELECT name FROM users WHERE city = 'Berlin';

The last statement returns Leo. You can paste queries like these into the online SQL editor to experiment, and tidy messy ones with the SQL formatter.

Relational vs NoSQL

Relational databases enforce a fixed structure: each table has defined columns, and tables link to each other through keys. That suits data with clear relationships, such as customers, orders, and products.

"NoSQL" covers several other designs. Document stores like MongoDB keep flexible, JSON-like records. Key-value stores like Redis are built for very fast lookups by a single key. They give up some of the structure and query power of SQL in exchange for flexibility or speed. Many applications use both: a relational database as the main store and Redis as a cache.

Your program usually reaches a database through a driver library written for your language.

Learn more

Last updated