Data Type and Constraint Reference
A reference for enterprise data modeling, architecture and industry exchange.
Select types that represent the domain without unintended loss. Distinguish identifiers from quantities, exact decimal values from approximate measurements, dates from timestamps, and bounded codes from free text. Consider range, precision, units, collation and timezone behavior.
Choose types from meaning
Select types that represent the domain without unintended loss. Distinguish identifiers from quantities, exact decimal values from approximate measurements, dates from timestamps, and bounded codes from free text. Consider range, precision, units, collation and timezone behavior.
Model nullability deliberately
A nullable field can represent unknown, unavailable or not applicable states, but those meanings are not interchangeable. If users must distinguish them, model an explicit status or reason. Use defaults only when they express a valid business rule rather than hiding missing information.
Use constraints as guardrails
Primary keys identify rows, unique constraints enforce uniqueness, foreign keys protect relationships, and checks constrain valid values. Choose database constraints and application or pipeline validations based on the platform and failure behavior. Document constraints that cannot be enforced physically.
Verify platform behavior
Type names, implicit conversions, precision limits and constraint enforcement vary by engine. Check official documentation for the target database before implementation. Test boundary values, invalid values, timezone conversions and migration effects.
Apply with care
Confirm definitions, current versions, usage rights and implementation expectations with authoritative sources and accountable domain owners. Record local mappings, assumptions and changes so consumers can understand the scope of the model.
Choose types by domain meaning
Decide whether a value is an identifier, quantity, measurement, label, date, instant or duration before choosing a storage type. An account number that contains digits is usually a label, not a quantity; arithmetic and leading-zero removal would be incorrect. Measurements need units and scale. Currency amounts need a currency and precision rule.
Define constraints and unknown states
Unique constraints, references, ranges and allowed values encode invariants. State where each rule is enforced and what happens when data violates it. A nullable field can represent several different states, so distinguish unknown, not yet received, not applicable and withheld when users need to interpret them differently.
Prefer explicit status or reason fields to arbitrary sentinel values. If a source contract requires a sentinel, map it at the boundary and retain the original meaning. Test default values so missing data does not silently look like a real measurement.
Check temporal and numeric edge cases
Dates, local times and instants are not interchangeable. State timezone, daylight-saving behavior and interval boundaries. For decimals, test maximum magnitude, scale, rounding and overflow. For text, define encoding, collation, normalization and case sensitivity when they affect identity or matching.
Review checklist
- Does the type match real operations and value range?
- Are units, precision and timezone defined?
- Are uniqueness and reference scopes explicit?
- Are missing states interpretable?
- Are invalid values rejected or routed observably?
Worked example: types and constraints
For an amount, choose a numeric representation with explicit scale and rounding rules; for an identifier that may contain leading zeroes, use a character representation rather than an arithmetic type. Store event instants with timezone-aware semantics where supported, and distinguish them from business dates. Type choice is part of meaning and can affect comparison, sorting, aggregation, and interchange.
Constraints should encode confirmed invariants: a required value, a unique business key, a valid range, or a relationship to an existing parent. Be cautious with rules that appear universal but have valid exceptions. If a constraint cannot be enforced in the storage layer, implement an equivalent check and make violations observable. Document who can authorize exceptions.
Test conversions and integrity
Use boundary values, maximum lengths, precision limits, invalid codes, nulls, and timezone boundaries in fixtures. Confirm how the target platform handles coercion and overflow. During migration, quantify rejected or changed values and provide a reconciliation plan. A successful cast does not prove that the converted value retained its intended business meaning.
Constraint operations and data repair
When an integrity check fails, preserve the offending key and context, identify the source owner, and define whether processing pauses or continues with a quarantine. Avoid disabling a constraint indefinitely to make a load pass. Record approval and a plan to restore enforcement after the repair.
After correction, validate affected relationships and aggregates, not just the individual row. Document platform-specific behavior such as deferred constraints or null uniqueness. Reconcile counts and retain migration evidence.
Manage constraint changes
Before tightening or relaxing a constraint, profile existing data, identify consumers, and plan remediation. Deploy checks before enforcement when needed, then monitor violations. Document approved exceptions and sunset plans.
Test migration behavior and rollback. Keep physical constraints aligned with semantic definitions and catalog documentation.
Use this reference during design review
For each field, record business meaning, range, units, null semantics, and interoperability. Confirm target platform limits and test casts. For constraints, identify the business invariant and exception path.
Update the model and tests together when a type or rule changes.