Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

175


Chapter 8: Data Types, Expressions, and Scalar Functions


8


Numeric Data Types
SQL Server supports several numeric data types, as listed in Table 8-2.

TABLE 8-2 Numeric Data Types

Data Type Description Size in Bytes
Bit 1 or 0 1 bit
Tinyint Integers from 0 to 255 1 byte
Smallint Integers from −32,768 to 32,767 2 bytes
Int Integers from −2,147,483,648 to 2,147,483,647 4 bytes
Bigint Integers from −2'63 to 2'63-1 8 bytes
Decimal or
Numeric

Fixed-precision numbers up to −10'38 + 1 Varies according to
length
Money Numbers from −2'63 to 2'63, accuracy to one
ten-thousandths (.0001)

8 bytes

SmallMoney Numbers from −214,748.3648 through
+214,748.3647, accuracy to ten thousandths
(.0001)

4 bytes

Float Floating-point numbers ranging from
−1.79E + 308 through 1.79E + 308, depending
on the bit precision

4 or 8 bytes

Real Float with 24-bit precision 4 bytes

Best Practice


When working with monetary values, be careful with the data type. Using float or real data types for
money causes rounding errors. The data types money and smallmoney are accurate to one hundredth
of a U.S. penny. For some monetary values, the client may request precision only to the penny, in which
case decimal is the more appropriate data type.

Date/Time Data Types
Traditionally, SQL Server stores both the date and the time in a single column using the
datetime and smalldatetime data types, as described in Table 8-3.

c08.indd 175c08.indd 175 7/30/2012 4:21:11 PM7/30/2012 4:21:11 PM


http://www.it-ebooks.info
Free download pdf