The storage sizes for datatypes are shown in Table 11-2:
Datatype |
Size |
---|---|
char |
Defined size |
nchar |
Defined size * @@ncharsize |
unichar |
n*@@unicharsize (@@unicharsize equals 2) |
univarchar |
the actual number of characters*@@unicharsize |
varchar |
Actual number of characters |
nvarchar |
Actual number of characters * @@ncharsize |
binary |
Defined size |
varbinary |
Data size |
int |
4 |
smallint |
2 |
tinyint |
1 |
float |
4 or 8, depending on precision |
double precision |
8 |
real |
4 |
numeric |
2–17, depending on precision and scale |
decimal |
2–17, depending on precision and scale |
money |
8 |
smallmoney |
4 |
datetime |
8 |
smalldatetime |
4 |
bit |
1 |
text |
16 bytes + 2K * number of pages used |
image |
16 bytes + 2K * number of pages used |
timestamp |
8 |
The storage size for a numeric or decimal column depends on its precision. The minimum storage requirement is 2 bytes for a 1- or 2-digit column. Storage size increases by 1 byte for each additional 2 digits of precision, up to a maximum of 17 bytes.
Any columns defined as NULL are considered variable-length columns, since they involve the overhead associated with variable-length columns.
All calculations in the examples that follow are based on the maximum size for varchar, univarchar, nvarchar, and varbinary data—the defined size of the columns. They also assume that the columns were defined as NOT NULL. If you want to use average values instead, see “Using average sizes for variable fields”.