SQL: Structured Query LanguageSQL FundamentalsRecords and Fields

What is a record, and how is it different from a field?

Question 7 of 30 · Updated

On this page

A record is a complete row of related values describing one occurrence of an entity or event. A field is an individual named piece of information within that record. For example, a device record may contain its ID, label and battery percentage; the battery percentage is one field of that record, not the entire record.

In everyday database terminology, people also use field to mean a column or attribute. To avoid ambiguity, distinguish the column definition (the named attribute shared by all rows) from the field value (the value of that attribute in one particular row). In SQL, row and column are usually the more precise terms.

1. Record versus field: a concrete example#

Consider a devices table in which each record represents one sensor:

device_idlabelbattery_pct
1Sensor A75
2Sensor B75
3Sensor CNULL

The record for Sensor A is the complete row (1, 'Sensor A', 75). Its three field values are 1, 'Sensor A' and 75. The column named battery_pct defines the battery attribute across all three records. The battery field value of device 1 is specifically 75.

FeatureRecordField
ScopeWhole row describing one occurrenceOne named attribute within a record, or its value
SQL terminologyRow; tuple in relational theoryColumn/attribute, or a column value in a particular row
Example(1, 'Sensor A', 75)battery_pct = 75
IdentityCan be identified by a primary keyA field value need not uniquely identify the record
QuantityOne row may contain many fieldsA column can have a value in many records

Both Sensor A and Sensor B have a battery percentage of 75, but they remain separate records with distinct device IDs. A repeated field value does not imply a duplicate record.

2. Create and populate the example#

Use a fresh disposable database for the examples. This lesson uses integer battery percentages and permits NULL when a reading has not been obtained.

SQL
CREATE TABLE devices ( device_id INTEGER PRIMARY KEY, label TEXT NOT NULL, battery_pct INTEGER CHECK (battery_pct BETWEEN 0 AND 100) ); INSERT INTO devices (device_id, label, battery_pct) VALUES (1, 'Sensor A', 75), (2, 'Sensor B', 75), (3, 'Sensor C', NULL);

The CREATE TABLE statement defines the columns. Each tuple in the INSERT statement supplies a new record. The values correspond to the listed target columns in order. The primary key identifies a device; the CHECK constraint rejects battery percentages outside the permitted range. SQL CHECK permits UNKNOWN as well as TRUE, so this nullable battery column can contain NULL. Use NOT NULL as well if an unknown battery percentage must not be stored.

3. Retrieve one complete record versus one field#

To retrieve the whole stored record for device 1, request every column in this example:

SQL
SELECT device_id, label, battery_pct FROM devices WHERE device_id = 1;
device_idlabelbattery_pct
1Sensor A75

To retrieve only its battery field value:

SQL
SELECT battery_pct FROM devices WHERE device_id = 1;

| battery_pct | |---:| | 75 |

The second query still returns a result row with one column. SQL does not change the stored record merely because the query projects fewer columns. An application may extract the scalar 75 from that result row, but the SQL result remains tabular.

Now look for all devices sharing the same battery value:

SQL
SELECT device_id, battery_pct FROM devices WHERE battery_pct = 75 ORDER BY device_id;
device_idbattery_pct
175
275

The filter matches two records because a battery percentage is not a unique identifier. When an application must select a single particular device, use its stable primary key rather than an arbitrary field value.

4. A record can exist even when a field value is missing#

Sensor C is a valid record even though its battery percentage is NULL. This represents a missing or unknown reading, not a zero-percent battery and not a missing device.

SQL
SELECT device_id, battery_pct FROM devices WHERE battery_pct IS NULL ORDER BY device_id;
device_idbattery_pct
3NULL

This distinction matters when counting records and values:

SQL
SELECT COUNT(*) AS records, COUNT(battery_pct) AS known_batteries FROM devices;
recordsknown_batteries
32

COUNT(*) counts every matching row. COUNT(battery_pct) counts matching rows for which that expression is not NULL, including repeated non-NULL values. It does not count distinct percentages unless DISTINCT is specified. The two aggregates answer different business questions: how many devices exist and how many have reported their batteries.

5. Updating one field within a record#

Suppose Sensor A reports a new battery percentage. You can update the field without supplying or replacing the entire logical record:

SQL
UPDATE devices SET battery_pct = 80 WHERE device_id = 1; SELECT device_id, label, battery_pct FROM devices ORDER BY device_id;
device_idlabelbattery_pct
1Sensor A80
2Sensor B75
3Sensor CNULL

The WHERE clause identifies the target record, while SET specifies the field to change. The label and ID of Sensor A remain unchanged in this example, and the other devices are unaffected. In production, triggers, generated columns or other database rules may introduce additional effects. Logically updating one field does not necessarily mean the storage engine modifies only one physical cell.

To see how a field-level rule protects the record, run this invalid statement separately:

SQL
UPDATE devices SET battery_pct = 101 WHERE device_id = 1;

The CHECK constraint rejects this update. If testing inside a PostgreSQL transaction, recover with a savepoint or roll back after a failed statement before proceeding.

6. PostgreSQL-specific distinction: a whole-row value#

PostgreSQL can also treat a row as a composite value containing named fields. The following read-only demonstration creates a single example row using VALUES, without a permanent table, and compares a representation of the whole row with one field:

SQL
SELECT row_to_json(d) AS whole_record, d.battery_pct AS field_value FROM (VALUES (1, 'Sensor A', 75)) AS d(device_id, label, battery_pct);
whole_recordfield_value
{"device_id":1,"label":"Sensor A","battery_pct":75}75

d is the whole-row reference, while d.battery_pct selects a single named field. row_to_json converts the composite row to a JSON object for display; it does not mean the stored relational row is inherently JSON. PostgreSQL also uses RECORD in procedural SQL for variables that can hold a row of an appropriate structure at runtime. Those more advanced meanings should not be confused with the everyday definition of a record as a table row.

Testing evidence: Seven checks passed in an isolated SQLite 3.46.1 in-memory database: five query results, the targeted field update with verification of all rows, and the invalid CHECK update. The exact PostgreSQL whole-row JSON query also passed through a read-only VALUES example. The SQLite table setup and updates were not run on the production PostgreSQL database; full cross-dialect validation of the DDL and constraints was not performed.

7. Common interview mistakes#

  • Calling the column header a record. The header names attributes; the rows contain records.
  • Using field ambiguously without clarifying whether it means the column definition or one value in a row.
  • Assuming identical values in one field make two records duplicates. Uniqueness depends on the chosen keys and business rules.
  • Confusing a NULL field with an absent record. A record can contain missing values.
  • Assuming COUNT(column) counts every record regardless of NULL.
  • Assuming a field update replaces the entire row or changes the same field in every record.

8. Interview-ready answer#

A record is a complete row in a table, containing related values that describe one entity or event. A field is one attribute of that record, or the value of that attribute in a particular row. For example, in a device table with device_id, label and battery_pct, the row for Sensor A is a record and its battery percentage of 75 is a field value. A column defines the attribute across all records, while a primary key can identify a particular record. Multiple records may share a field value, and a record may exist even if a nullable field is missing.

Related questions

Explore other topics:Forward Deployed EngineeringPythonAI System DesignMachine Learning

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.