In SQL Server you can use FLOAT
or REAL
to store floating point values the storage format of which is cleared defined by the IEEE 754 standard. For fixed point values we can use DECIMAL
type (which has a synonym NUMERIC
). However I'm not pretty sure how SQL Server store DECIMAL
values internally. For example, if I define a table and insert a row like this:
IF OBJECT_ID('dbo.test_number_types') IS NOT NULL DROP TABLE dbo.test_number_types;
CREATE TABLE dbo.test_number_types
(
id INT IDENTITY(1, 1),
c1 NUMERIC(5, 4)
)
GO
INSERT INTO dbo.test_number_types(c1)VALUES(5.7456);
When I use DBCC PAGE
command to check how SQL Server stores the number 5.7456, I got this:
01 70 E0 00 00
This hex string should use little endian. I can't figure out how SQL Server turns 5.7456 into 01 70 E0 00 00
and how it decides how many bytes are for the integral part and how many bytes are for the decimal parts. Can anyone help?
BTW, I've checked the book "SQL Server 2012 Internals". There is a chapter dedicated to data type storage. But it seems DECIMAL
type storage is not mentioned in the book.