Column · databases

Also known as: field · attribute

On this page 7

A column in relational databases is a named attribute of a table that stores one kind of value for every row, with a declared data type and optional rules that restrict what may be stored. In database fundamentals, the column is also called a field or, in relational theory, an attribute, and it defines the vertical dimension of a table while rows define the horizontal one.

Every value in a table sits at the intersection of exactly one row and one column. The set of columns, together with their types and constraints, forms the core of a table’s schema, so designing columns well is one of the earliest and most consequential decisions in data modeling.

What a column defines in a table

A column defines the meaning, type and rules for a single property that all rows of a table share. Its definition is written in the CREATE TABLE statement and stored in the system catalog, the metadata that the database management system consults on every query.

A column definition is built from several parts. The table below lists the main components and their effect on stored data.

ComponentExampleEffect
Nameorder_dateIdentifies the column in queries
Data typeDATE, VARCHAR(100)Limits values and sets storage format
NullabilityNOT NULLDecides whether a value may be missing
Default valueDEFAULT CURRENT_DATESupplies a value when none is given
ConstraintCHECK (price >= 0)Rejects values that break a rule
CollationCase-insensitive collationControls text comparison and sorting
Components of a column definition

In relational theory, each attribute draws its values from a domain, the set of permitted values. SQL approximates domains through data types and constraints. Because the order of columns carries no meaning in the relational model, well-written queries name columns explicitly rather than relying on their position.

Column data types and storage

The data type of a column determines which values are valid, how much space they use and how they compare. Choosing the narrowest type that safely covers the real range saves disk space, memory and index size, and it also catches invalid input early.

Type familyTypical typesStorage and notes
IntegerSMALLINT, INTEGER, BIGINT2, 4 or 8 bytes; exact whole numbers
Exact decimalNUMERIC(p,s), DECIMALVariable size; required for money
Floating pointREAL, DOUBLE PRECISION4 or 8 bytes; approximate values
CharacterCHAR(n), VARCHAR(n), TEXTLength depends on content and encoding
TemporalDATE, TIMESTAMP, INTERVALFixed size; supports date arithmetic
BooleanBOOLEANUsually 1 byte; true, false or NULL
Semi-structuredJSON, JSONB, XMLFlexible content; weaker type checking
Common SQL column types

Exact names and limits vary between systems, so a design should be checked against the specific product. A frequent and costly error is storing currency in floating-point columns, which introduces rounding differences; financial amounts belong in exact decimal types or in integer minor units such as cents.

Column compared with row, field and key

A column describes one property across all records, whereas a row describes one record across all properties. The terminology overlaps between communities, which is why the same idea appears under several names.

TermMeaningRelation to a column
ColumnNamed, typed property of a tableThe concept itself
AttributeRelational theory name for a columnFormal synonym
FieldColumn, or a single value in one recordSynonym; meaning depends on context
RowOne record holding a value per columnCrosses every column once
Primary keyColumn or columns that identify each rowBuilt from one or more columns
Foreign keyColumn referencing another table’s keyA column with a referential rule
IndexStructure that speeds lookups on columnsDefined over one or more columns
Related terms in database fundamentals

A column becomes a key not by its type but by the constraint declared on it. A single column can serve as a primary key, a composite key can span several columns, and a foreign key column enforces referential integrity by allowing only values that exist in the referenced table.

Designing and changing columns

Good column design follows the principle of atomic values, which is the core of first normal form: each column holds one indivisible fact. A column that stores a comma-separated list of tags or a full address in one string makes filtering, validation and indexing difficult.

  • Use consistent naming, such as lowercase words separated by underscores, and avoid reserved words like order or user.
  • Declare NOT NULL by default and allow NULL only where a missing value has a clear meaning.
  • Add CHECK and UNIQUE constraints so the database, not only the application, protects data quality.
  • Avoid repeating groups such as phone1, phone2, phone3; move them into a related table instead.

Columns change over a system’s lifetime through ALTER TABLE. The cost of a change depends heavily on the operation and the product, as the following table shows in general terms.

ChangeUsual impactPrecaution
Add a nullable columnOften a fast metadata changeBackfill data in small batches
Add a column with a defaultFast in many modern systemsCheck the product version
Change the data typeMay rewrite the whole tableUse a new column and migrate
Rename a columnFast, but breaks dependent codeUpdate views, procedures and ORM mappings
Drop a columnFast or deferred cleanupConfirm no query still reads it
Typical cost of column changes on a large table

Row stores and column stores

The column also shapes physical storage. A row-oriented store keeps all columns of a record together on disk, which suits OLTP workloads that read or write whole records. A column-oriented store keeps the values of each column together, which suits analytics that scan a few columns across millions of rows.

Columnar layout compresses well because neighboring values share a type and often repeat, and queries read only the columns they need. The trade-off is slower single-record inserts and updates, which is why many organizations keep transactional data in a row store and copy it to a columnar warehouse for reporting.

The idea in brief

Think of a spreadsheet of customers. Each column has a heading, such as Name, Email or Birth date, and holds the same kind of information for every person in the list. A database column works the same way, but it is stricter.

The database knows what kind of data each column accepts. A date column will refuse the word hello, and a price column can be told never to accept a negative number. These rules keep the information clean and trustworthy, so reports and applications built on top of it give correct results.

A practical scenario

A small online bookstore stores its orders in a table whose total column was originally declared as a floating-point type. After a year, the monthly revenue report differs from the payment provider’s statement by a few cents, and accountants spend hours reconciling the gap.

A database administrator adds a new column total_amount of type NUMERIC(10,2) with a CHECK (total_amount >= 0) constraint, copies the values in batches of 10,000 rows, switches the application to the new column and finally drops the old one. A NOT NULL constraint is added once the backfill is complete.

The migration runs without downtime because each step is small. From the next month on, the report matches the payment statements to the cent, and an attempted import of a negative order total is now rejected by the database itself instead of reaching the books.