176
Part II: Building Databases and Working with Data
TABLE 8-3 Date/Time Data TypesData Type Description Size in Bytes
Datetime Date and time values from January 1, 1553 (begin-
ning of the Julian calendar) through December
31, 9999, accurate to 3 milliseconds8 bytesSmalldatetime Date and time values from January 1, 1900
through June 6, 2079, accurate to 1 minute4 bytesDateTime2() Date and time values January 1, 0001 through
December 31, 9999 (Gregorian calendar), variable
accuracy from .01 seconds to 100 nanoseconds6–8 bytes depend-
ing on precisionDate Date and time values January 1, 0001 through
December 31, 9999 (Gregorian calendar)3 bytesTime(2) Time values, variable accuracy from .01 seconds
to 100 nanoseconds3–5 bytes depend-
ing on precision
Datetimeoffset Date and time values January 1, 0001 through
December 31, 9999 (Gregorian calendar), variable
accuracy from .01 seconds to 100 nanoseconds,
includes embedded time zone8–10 bytes depend-
ing on precisionSome programmers (non-DBAs) choose character data types for date columns. This can cause a horrid conversion
mess. Use the ISDATE() function to sort through the bad data.Other Data Types
Other data types, as shown in Table 8-4, fulfi ll the needs created by unique values, binary
large objects, and variant data.TABLE 8- 4 Other Data TypesData Type Description Size in Bytes
Timestamp or
RowversionDatabase-wide unique random value
generated with every update based on
the transaction log LSN value8 bytesUniqueidentifier System-generated 16-byte value 16 bytes
Binary(n) Fixed-length data up to 8,000 bytes Defi ned length
VarBinary(max) Fixed-length data up to 8,000 bytes Defi ned lengthc08.indd 176c08.indd 176 7/30/2012 4:21:11 PM7/30/2012 4:21:11 PM
http://www.it-ebooks.info