Thursday, March 5, 2015

SQL Server 2012 Data types

DATATYPEMINMAXSTORAGETYPENOTES
Bigint-2^632^63-18 bytesExact
Int-2,147,483,6482,147,483,6474 bytesExact
Smallint-32,76832,7672 bytesExact
Tinyint02551 bytesExact
Bit011 to 8 bit columns in the same table requires a total of 1 byte, 9 to 16 bits = 2 bytes, etc...Exact
Decimal-10^38+110^38–1Precision 1-9 = 5 bytes, precision 10-19 = 9 bytes, precision 20-28 = 13 bytes, precision 29-38 = 17 bytesExactThe Decimal and the Numeric data type is exactly the same. Precision is the total number of digits. Scale is the number of decimals. For both the minimum is 1 and the maximum is 38.
Numericsame as Decimalsame as Decimalsame as DecimalExact
Money-2^63 / 100002^63-1 / 100008 bytesExact
Smallmoney-214,748.3648214,748.36474 bytesExact
Float-1.79E + 3081.79E + 3084 bytes when precision is less than 25 and 8 bytes when precision is 25 through 53ApproxPrecision is specified from 1 to 53.
Real-3.40E + 383.40E + 384 bytesApproxPrecision is fixed to 7.
Datetime1753-01-01 00:00:00.0009999-12-31 23:59:59.9978 bytesDatetimeIf you are running SQL Server 2008 or later and need milliseconds precision, use datetime2(3) instead to save 1 byte.
Smalldatetime1900-01-01 00:002079-06-06 23:59Datetime
Date0001-01-019999-12-313 bytesDatetime
Time00:00:00.000000023:59:59.9999999DatetimeSpecifying the precision is possible. TIME(3) will have milliseconds precision. TIME(7) is the highest and the default precision. Casting values to a lower precision will round the value.
Datetime20001-01-01 00:00:00.00000009999-12-31 23:59:59.9999999Presicion 1-2 = 6 bytes precision 3-4 = 7 bytes precision 5-7 = 8 bytesDatetimeCombines the date datatype and the time datatype into one. The precision logic is the same as for the time datatype.
Datetimeoffset0001-01-01 00:00:00.0000000 -14:009999-12-31 23:59:59.9999999 +14:00Presicion 1-2 = 8 bytes precision 3-4 = 9 bytes precision 5-7 = 10 bytesDatetimeIs a datetime2 datatype with the UTC offset appended.
Char0 chars8000 charsDefined widthStringFixed width
Varchar0 chars8000 chars2 bytes + number of charsStringVariable width
Varchar(max)0 chars2^31 chars2 bytes + number of charsStringVariable width
Text0 chars2,147,483,647 chars4 bytes + number of charsStringVariable width
Nchar0 chars4000 charsDefined width x 2UnicodeFixed width
Nvarchar0 chars4000 charsUnicodeVariable width
Nvarchar(max)0 chars2^30 charsUnicodeVariable width
Ntext0 chars1,073,741,823 charsUnicodeVariable width
Binary0 bytes8000 bytesBinaryFixed width
Varbinary0 bytes8000 bytesBinaryVariable width
Varbinary(max)0 bytes2^31 bytesBinaryVariable width
Image0 bytes2,147,483,647 bytesBinaryVariable width. Prefer to use the varbinary(max) type as the image type will be removed in future versions.
Sql_variantOtherStores values of various SQL Server-supported data types, except text, ntext, and timestamp.
TimestampOtherStores a database-wide unique number that gets updated every time a row gets updated.
UniqueidentifierOtherStores a globally unique identifier (GUID).
XmlOtherStores XML data. You can store xml instances in a column or a variable.
CursorOtherA reference to a cursor.
TableOtherStores a result set for later processing.

No comments:

Post a Comment