SQL Server: what data type for decimal measure values?
When building data marts for reporting purposes (using dimensional modelling), what dat开发者_StackOverflow中文版a types should I use for decimal measure values (for fast operations)? Numeric, decimal or money?
Numeric = Decimal. Different name, same data type.
As for money, see this interesting test done by Aaron Bertrand
https://sqlblog.org/2008/04/27/performance-storage-comparisons-money-vs-decimal
The long and short is that decimal is faster (marginally) than money and more flexible; money is really only meant for currency and is locked to 4dp. If you are modeling and floating point maths is acceptable, consider floating-point maths using float/real, which is native on the CPU (there are floating point registers, but not decimal). Floats are always faster than decimals.
Decimal looks fine, and you can define the precision you need.
Single / float if you want FAST. Once you get into aggregation etc. - they are faster in procecessing as decimal as they are directoy OS supported for maths.
But then, you should not build the mart for reporting in SQL server, but in the SSAS subsystem.
精彩评论