Microsoft Azure Data FundamentalsDescribe how to work with relational data on AzureMedium

A development team is building a new application that uses Azure SQL Database. The application will store monetary values, such as product prices and transaction amounts. These values require exact precision and scale, and should not be subject to floating-point inaccuracies. Which data type should the team use to store these monetary values?

  1. AREAL
  2. BFLOAT
  3. CMONEY
  4. DDECIMAL
Show answer & explanation

Correct answer: D. DECIMAL

The DECIMAL data type stores exact numeric values with a fixed precision and scale, making it ideal for monetary data where floating-point inaccuracies are unacceptable. FLOAT and REAL are approximate numeric types, and MONEY has limitations on precision and scale compared to DECIMAL.

Why the other options are wrong

  • A. REAL is also an approximate numeric data type (single-precision floating point) and has even less precision than FLOAT, making it highly unsuitable for financial data.
  • B. FLOAT is an approximate numeric data type and can suffer from precision errors, making it unsuitable for monetary values that require exact representation.
  • C. MONEY is a SQL Server-specific data type designed for monetary values, but it has a fixed scale of 4 decimal places and a limited range. DECIMAL offers more flexibility in precision and scale and is generally preferred for modern applications requiring exactness.

DECIMAL Data Type

An exact numeric data type in SQL Server that stores values with a fixed precision and scale, ensuring accuracy for calculations like monetary values.

  • Stores exact numeric values.
  • Precision (total digits) and scale (digits after decimal) are user-defined.
  • Avoids floating-point inaccuracies.
  • Ideal for financial calculations, measurements, and other precise numeric data.

Memory trick: DECIMAL for dollars, FLOAT for flexible, REAL for reckless.

More Describe how to work with relational data on Azure questions