According to BOL for SQL Server 2008 R2 the data type decimal requires the following storage bytes:
Precision Storage bytes
1 - 9 => 5
10-19 => 9
20-28 => 13
29-38 => 17
However, when I do a datalength() on a column that is formatted decimal(19,5) and has the value of 10999.99999 I get back 5 bytes ? Which is according to my understanding a precision of 10 and not of 9 and should result in 9 bytes.
this results in two questions:
is the size of the table with this column not depending on the column definition, instead the true values within the column define the table size ?
why is the information in BOL not matching with what datalength() returns ?
DATALENGTHreporting 5 or 9 bytes in this instance seems to be42949.67295(stored as01 FF FF FF FF 00 00 00 00) and42949.67296(stored as01 00 00 00 00 01 00 00 00). Not sure how useful that behaviour is exactly! – Martin Smith Nov 14 '11 at 17:34CREATE TABLE [Test195]( [Date] [date] NULL, [Time] [time](3) NULL, [CCYPairID] [tinyint] NULL, [Price] [decimal](19, 5) NULL, [Amount] [bigint] NULL, )SELECT [Date] ,[Time] ,[CCYPairID] ,DATALENGTH([CCYPairID]) as CByte ,[Price] ,DATALENGTH([Price]) as PByte ,[Amount] ,DATALENGTH([Amount]) as AByte FROM [Test195]– nojetlag Nov 14 '11 at 17:55