Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server?

前端 未结 12 2239
时光取名叫无心
时光取名叫无心 2020-11-22 03:45

I\'m curious as to whether or not there is a real difference between the money datatype and something like decimal(19,4) (which is what money uses

12条回答
  •  长情又很酷
    2020-11-22 04:00

    I found a reason about using decimal over money in accuracy subject.

    DECLARE @dOne   DECIMAL(19,4),
            @dThree DECIMAL(19,4),
            @mOne   MONEY,
            @mThree MONEY,
            @fOne   FLOAT,
            @fThree FLOAT
    
     SELECT @dOne   = 1,
            @dThree = 3,    
            @mOne   = 1,
            @mThree = 3,    
            @fOne   = 1,
            @fThree = 3
    
     SELECT (@dOne/@dThree)*@dThree AS DecimalResult,
            (@mOne/@mThree)*@mThree AS MoneyResult,
            (@fOne/@fThree)*@fThree AS FloatResult
    

    DecimalResult > 1.000000

    MoneyResult > 0.9999

    FloatResult > 1

    Just test it and make your decision.

提交回复
热议问题