In relational database design, which column property should you choose to ensure that every cell in a column stores a monetary value (for example, prices in ₹ or $), with an appropriate numeric precision and scale?

Difficulty: Easy

Correct Answer: Data type

Explanation:


Introduction / Context:
When creating tables, one of the most important choices is the column's data type. For money-like values (such as prices, totals, taxes, and discounts), the data type determines how values are stored, their precision, and how arithmetic behaves. Choosing the right property avoids rounding errors and guarantees that each value is treated as numeric currency rather than as free text.



Given Data / Assumptions:

  • We are defining a column that must store monetary values (₹, $, or other currency units).
  • We want predictable arithmetic and exact storage of decimals where possible.
  • The database is a relational DBMS such as PostgreSQL, SQL Server, MySQL, or Oracle.


Concept / Approach:
The data type is the column property that enforces what kind of data can be stored. For currency, fixed-point numeric types (for example, DECIMAL(p,s) or NUMERIC(p,s)) are preferred because they support exact arithmetic with a defined precision (p) and scale (s). Other properties (NULL status, default values, constraints) refine behavior, but the foundational guarantee that a column holds monetary numbers comes from the data type.



Step-by-Step Solution:

Identify the requirement: store currency values accurately.Select a fixed-point numeric data type: DECIMAL or NUMERIC with appropriate precision/scale (for example, NUMERIC(12,2)).Optionally add CHECK constraints to enforce nonnegative values or maximum limits, and add a DEFAULT if needed.Document the unit (₹ or $) at the application or view layer to avoid ambiguity.


Verification / Alternative check:
Insert typical values (for example, 199.99, 0.05, 9999999.99) and perform arithmetic. Confirm that results are exact under DECIMAL/NUMERIC and that the DBMS prevents non-numeric input.



Why Other Options Are Wrong:

  • Null status: Controls presence/absence of a value, not whether it is monetary.
  • Default value: Supplies an initial value but does not enforce numeric currency type.
  • Data constraints: Helpful for ranges or positivity, but they complement, not replace, the data type.
  • Collation: Applies to text sorting/comparison, irrelevant for numeric currency.


Common Pitfalls:
Using floating-point types (REAL/DOUBLE) for money can introduce rounding errors. Always choose fixed-point NUMERIC/DECIMAL for financial calculations.



Final Answer:
Data type

More Questions from Data Models into Database Designs

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion