Search
Home
Articles
Backup
Books
Certification
FAQ
Products
Replication
Scripts
Seminars
Training
TSQL

MSDN Fourms
Fort Worth SSUG
Oklahoma City SSDG

Resume

Champion Valley Pens

SQL Server 7.0 Datatypes 1 2 3 4 5 6

Fixed Numeric Datatypes
Datatype Range of values Storage Space
int or integer -2,147,483,648 to 2,147,483,647 4 bytes
smallint -32,768 to 32,767 2 bytes
tinyint 0 to 255 1 byte

After stressing the importance of choosing the appropriate datatype, I am going to give you a rule that violates it. Unless storage space is at an absolute premium, use an integer datatype. Intel processors, which is the predominant processor SQL Server runs on, are architected to work with 4 bytes at a time. This means an integer is the optimal size for the processor. Since it is the optimal size, integers will normally process faster than smallint or tinyint. If you need to restrict the range of values on the column, defining an integer column with a constraint is actually more efficient than using a smallint or tinyint.

Exact Numeric Datatypes

This group of datatypes gets its name from the fact that it stores an exact precision for all decimal data. Within the notations, p respresents the precision and s represenst the scale. The precision specifies the total number of digits allowed. The scale specifies the total number of digits to the right of the decimal. You will note in the table below that both datatypes have the same range of values and require the same space. Each of these datatypes is exactly equivalent. You should be using decimal in yrou table definitions as numeric has been retained mainly for backward compatibility.

Datatype Range of values Storage Space
decimal(p,s) -1038 to 1038 2 to 17 bytes
numeric(p,s) -1038 to 1038 2 to 17 bytes

Space allocations

Precision Bytes of Storage
1 - 2 2
3 - 4 3
5 - 7 4
8 - 9 5
10 - 12 6
13 - 14 7
15 - 16 8
17 - 19 9
20 - 21 10
22 - 24 11
25 - 26 12
27 - 28 13
29 - 31 14
32 - 33 15
34 - 36 16
37 - 38 17

SQL Server 7.0 Datatypes 1 2 3 4 5 6

Michael R. Hotek

All content on this site, except where noted, represents an original work of Michael R. Hotek and is protected by applicable copyright laws. The SQL Server FAQ is the sole work of Neil Pike. No page, portion of a page, or download may be used for commercial purposes in whole or in part without the express, written permission of the applicable author.