How does SQL Server store decimal type values internally?

空扰寡人 提交于 2019-12-04 10:08:34

Martin's Smith comment gives you the clue. SQL Server does not use BCD. It stores the data as a whole number, without the decimal place (which it can do because the decimal place is stored in the metadata for the column). So 5.7456 is stored as 57456, or 0xE070. After SQL's infamous byte swapping this is transformed to 70 E0 00 00.

The leading 01 is the sign. 01 is used for positive numbers; 00 for negatives.

(However, I must ask - why do you need this? In typical use, you should never need to bother with SQL Server's internals)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!