Coding

What Is a Data Base? Database Types and Uses Explained

A database (also written "data base") is an organized collection of data that software can store, search and update. Most are run through a database management system, such as PostgreSQL, SQLite or MongoDB, which handles storage, queries and access for the programs that use it.

If you have ever logged in to a website, searched a product catalogue or opened a phone app that remembers your settings, a database was almost certainly involved somewhere behind it.

What a database actually is

Two things get called "the database", and it helps to separate them. The first is the data itself: the stored customers, orders, messages or readings. The second is the database management system (DBMS), the software that stores that data, answers questions about it and decides who may change it. When someone says "we run PostgreSQL", they mean the DBMS.

The reason to use a DBMS instead of a plain text file is that the software does the hard parts for you. You describe what you want, such as "all orders from this customer in March", and the system finds them without you writing code to scan a file. It also lets several programs read and write at the same time without trampling each other's changes.

How a relational database is organized

The most common kind is the relational database. The PostgreSQL documentation puts it this way: PostgreSQL is a relational database management system, meaning "a system for managing data stored in relations", and a relation is essentially a table. Each table is a named collection of rows. Each row of a given table has the same set of named columns, and each column has a specific data type, such as a number, a piece of text or a date.

A small example, written as SQL. This is an illustration, not output from a particular system:

CREATE TABLE customers (
  id    INTEGER PRIMARY KEY,
  name  TEXT,
  email TEXT
);

INSERT INTO customers (id, name, email)
VALUES (1, 'Alex', '[email protected]');

SELECT name FROM customers WHERE id = 1;

The first statement defines a table with three columns. The second adds one row. The third asks for the name in the row whose id is 1. The same shape scales to millions of rows, and tables can reference each other. An orders table might store a customer id instead of repeating the customer's name, and you combine the two at query time. That combining is called a join, covered in SQL joins explained. If you want to start writing queries, SQL for beginners is the next step.

One detail from the PostgreSQL tutorial surprises newcomers: columns have a fixed order within a row, but SQL does not guarantee the order of rows in a table. If you want rows in a particular order, you have to ask for it when you query.

Types of databases

"Database" covers several designs. The common ones, and what each is built for:

TypeHow data is storedExamplesTypical use
RelationalTables of rows and typed columns, queried with SQLPostgreSQL, SQLiteOrders, accounts, inventory, anything with clear structure
DocumentDocuments grouped into collections, each with its own fieldsMongoDBRecords whose shape varies or changes often
EmbeddedA database engine inside the application, often one fileSQLiteApps, devices and tools that need local storage
VectorNumeric embeddings searched by similaritySee the linked articleAI search and retrieval

These categories overlap. SQLite is both relational and embedded, for example. They describe different questions: how the data is shaped, and where the engine runs.

Document databases

The MongoDB manual describes documents whose field values can be any BSON data type, "including other documents, arrays, and arrays of documents." Documents in a single collection are "not required to have the same set of fields or data types." Its example is a clothing store whose products have different attributes but live in the same collection. The manual also says you can add new fields without running a schema migration, and can enforce a fixed structure with schema validation if you want one.

The trade-off is planning. The same manual notes that a relational schema "requires more planning upfront", and its design advice is that data accessed together should be stored together. That is a different habit from splitting data across many linked tables.

Embedded databases

SQLite is a relational database that runs inside your program rather than as a separate server. Its documentation says it "requires no administration", which is why it suits phones, thermostats and other devices that run without expert support. It can also serve as an application file format, replacing the File/Save step, because updates happen automatically.

Vector databases

A newer category stores numeric embeddings and finds the closest matches, which is how many AI search features work. It is a different job from looking up a row by id; see what is a vector database.

When SQLite is enough and when you need a server

The SQLite documentation is unusually direct about its limits. It says a client/server database is usually the better choice in these cases:

  • The data is on a different machine from the application, so every read would cross a network.
  • Many clients access the same database over a network. SQLite's page warns that file locking is "buggy in many network filesystem implementations", which can cause corruption.
  • Many writers need to write at once. SQLite allows unlimited readers but only one writer at a time. Write transactions are usually short, so writers can take turns.
  • The data is heading toward terabyte scale. The page suggests considering a client/server engine as data approaches that range.

Otherwise, for device-local storage with modest write concurrency, SQLite is a reasonable fit. The same page says sites with fewer than 100K hits per day should work fine, and reports that SQLite has handled about ten times that. These figures come from the SQLite project and describe its own experience, so test with your own workload.

Databases and data warehouses

A database that runs your application, handling many small reads and writes as users click around, is a different tool from one built to analyze large volumes of historical data. The second is a data warehouse, explained in what is a data warehouse. Many organizations run both: the application database records what happens, and the warehouse is where it gets analyzed.

Common beginner mistakes

  • Treating a spreadsheet as the database. Spreadsheets work for one person editing a grid. They do not enforce column types or handle several programs updating at once.
  • Assuming row order. Without an explicit sort in the query, SQL makes no promise about the order of rows.
  • Choosing a type by fashion. Pick based on the shape of your data and how many clients will write to it, not on which product is popular this year.
  • Exposing the database directly. Queries built by pasting user input into SQL text are open to injection; see SQL injection explained.

Frequently asked questions

Is a database the same as a spreadsheet?
No. A spreadsheet is a file you edit by hand in a grid. A database is managed by software that lets many programs read and change the data by query, and that enforces column types. A relational table looks like a sheet, but each column has a fixed data type and the system handles the querying.
What is the difference between a database and a DBMS?
The database is the stored data. The database management system (DBMS) is the software that stores it, answers queries and controls access. PostgreSQL, SQLite and MongoDB are database management systems, though people often call them databases.
Do I need SQL to use a database?
Relational databases such as PostgreSQL and SQLite are queried with SQL. Document databases such as MongoDB use their own query API instead. Which one you need depends on the system you pick.
Which database should a beginner start with?
SQLite is a common first choice because it needs no server or administration: the whole database is one file. Once you need many users writing at the same time over a network, a client/server system such as PostgreSQL is the usual next step.

Sources