Database
База данных
An organized collection of data that software can search and update. An online store, for instance, might use one to keep track of customers, products, and orders.
Also known as: БД, DB
What a database is
When you open your order history, the store doesn't need to read every receipt or store a separate copy of the page. It can ask its database for the orders that belong to your account. The database is the organized data; the database management system (DBMS) is the software that stores it and processes requests. PostgreSQL is a DBMS, while the store's collection of order and customer records is a database.
How data is organized and retrieved
A relational database organizes data into tables. Each row represents a record, and each column stores a particular attribute. A primary key identifies a row, and a foreign key can enforce a relationship between tables. For example, an order can carry a customer ID that must match a row in the customers table. A document database such as MongoDB represents records as documents, which can contain nested objects and arrays. The right model depends on how the application reads and updates its data.
When an application sends a query, the database engine decides how to find the requested records. It might scan a table or use an index to narrow the search. The DBMS can also enforce rules when data changes. For example, it can reject an order that refers to a nonexistent customer. A transaction groups changes so that they can be committed together or rolled back together.
Example: looking up orders
Suppose orders has one row per order. This SQL query gets the order IDs and statuses for a single customer and lists newer orders first:
SELECT id, status
FROM orders
WHERE customer_id = 42
ORDER BY created_at DESC;
An index on customer_id can help if the table is large and only a small fraction of orders belong to that customer. It does not necessarily remove the need to sort the results by created_at.
Where databases fit
Operational databases handle day-to-day work such as placing orders and updating inventory. Analytical databases are designed for workloads such as aggregating a year's sales across millions of records. SQL is a language, not a storage engine, and a database doesn't have to run on a separate server: SQLite runs inside the application and commonly stores the database in a local file.
What interviewers look for
A common exercise is to sketch a schema for customers and orders, then explain how to query it. Start with the operations the app needs to support. If it often looks up a customer's orders, an index may help; if checkout must create an order and reserve stock together, use a transaction. Explain the trade-offs as well: indexes take space, and writes that affect them must maintain them.