What Is a Database Column? Choosing Meaning, Types, and Constraints
A database column is a named part of a table that holds values of the same kind for each row. For example, a `quantity` column stores the quantity for each order item. Good column design specifies more than a name: its data type, whether it may be absent, and whether values may repeat all affect the meaning and quality of the data.
How do columns relate to rows?
A table defines columns, and each row supplies values for those columns. In an order-item table with an order ID, product ID, quantity, and unit price, one row represents one item in an order while each column describes one attribute. “Column” is a logical data-structure concept; it does not promise that values are physically stored in a vertical sequence on a storage device.
CREATE TABLE order_items (
order_id bigint NOT NULL,
line_no integer NOT NULL,
product_id bigint NOT NULL,
quantity integer NOT NULL CHECK (quantity > 0),
unit_price numeric(12, 2) NOT NULL CHECK (unit_price >= 0),
note text,
PRIMARY KEY (order_id, line_no)
);quantity is an integer and must be positive. unit_price is numeric with a declared precision and scale and cannot be negative. note has no NOT NULL rule, so it may be absent. The pair order_id and line_no identifies an item within an order. This DDL illustrates structure and constraints; it has not been run against a database.
What do names and data types determine?
A column name is part of the contract that helps people understand the data. unit_price communicates more than a vague name such as value. A name alone does not validate input, however. The data type limits the kinds of values and gives them meaning for operations. An integer suits quantities without fractions; a date type suits calendar dates; a string type suits text. PostgreSQL includes types such as integer, numeric, text, date, and timestamp. Other products may use different names or detailed rules, so check their documentation.
Storing money in an approximate floating-point type such as real can introduce rounding effects in calculations. An exact numeric type such as numeric, with chosen precision and scale, is often more appropriate for amounts. Business rules still need to define currency, rounding points, and acceptable ranges. A data type alone cannot express every domain rule.
How should you choose NULL, defaults, and constraints?
NULL marks a value that is absent or unknown; it is not zero or an empty string. Apply NOT NULL when the value must be supplied. A DEFAULT provides a value when an insert omits the column, but that differs from explicitly supplying NULL. A default does not prove that the value is correct for the business.
Constraints let the database reject values that violate rules on a column or a combination of columns. CHECK (quantity > 0) limits the quantity stored in a row; UNIQUE prevents repeated values or combinations. A PRIMARY KEY identifies rows and requires uniqueness and non-NULL values. A foreign key expresses a reference between tables. Constraints complement application validation by protecting invariants regardless of which application path writes the data.
Do not assume CHECK alone makes a value mandatory. PostgreSQL documents that a check can pass when its expression is true or NULL, so use NOT NULL separately to reject NULL. Also, a check constraint is generally suited to conditions on the current row, not rules that depend on changes to other rows or tables. Use an appropriate structure such as unique or foreign-key constraints for those relationships.
What should you check before changing a column?
Changing a column’s type, nullability, or name, or adding a constraint, can affect existing data and the applications that read or write it. For example, adding NOT NULL to a nullable column requires dealing with existing NULL rows first. Changing a text column to a numeric type requires checking for values that cannot be converted and whether the conversion preserves meaning. Before deployment, inspect the affected data, dependent queries and code, and prepare a backup plus a rollback or staged migration plan. Exact locking and online-change procedures depend on the database product and version.
For a new column, a practical review is:
Define the business fact it stores; make its name and unit clear.
Choose a type that fits its range and operations.
Decide whether the value is required and whether a default matches the real rule.
Express duplicate, range, and reference rules with suitable constraints and keys.
Check that existing data and applications can handle the change; after deployment, inspect constraint violations and results.
Sources and scope
[PostgreSQL 18: Table Basics](https://www.postgresql.org/docs/18/ddl-basics.html)
[PostgreSQL 18: Constraints](https://www.postgresql.org/docs/18/ddl-constraints.html)
[PostgreSQL 18: Data Types](https://www.postgresql.org/docs/18/datatype.html)
[PostgreSQL 18: Modifying Tables](https://www.postgresql.org/docs/18/ddl-alter.html)
The PostgreSQL 18 documentation was checked on 2026-11-22. The general idea of a column is explained in relational-table terms; concrete types, constraints, and DDL behavior are scoped to PostgreSQL. SQL is illustrative and was not executed. Check the relevant product documentation for compatibility, locking, and migration behavior in other databases.