Vous êtes sur la page 1sur 1

12 Chapter 1: Creating

1.5.5 Binary Integers


Binary integers are very popular when computational efficiency is a primary
concern. Binary computers can often perform calculations involving 2- and
4-byte binary integers much faster than other data types.
SQL Anywhere provides unsigned binary integers containing 1, 8, 16, 32,
and 64 binary digits, and signed values with 15, 31, and 63 digits plus a sign bit.
These are exact data types, similar in usefulness to DECIMAL ( p, 0 ) values.
<integer_type> ::= BIT
| [ UNSIGNED ] TINYINT
| [ UNSIGNED ] SMALLINT
| [ UNSIGNED ] ( INT | INTEGER )
| [ UNSIGNED ] BIGINT
The BIT data type is useful for boolean data where 0 represents FALSE and 1 is
TRUE. A full byte of physical storage is used for each value but only the values
0 and 1 are allowed.
By default, BIT columns are created as NOT NULL but can be explicitly
created as NULL. This differs from other data types where NULL is the
CREATE TABLE default and NOT NULL must be explicitly specified.
The TINYINT and UNSIGNED TINYINT data types are the same: an
unsigned binary integer in the range 0 to 255 requiring 1 byte of storage. This
data type is useful for very small positive numbers including primary keys for
tiny code tables.
The SMALLINT data type requires 2 bytes of storage and holds values in
the range 32,768 to 32,767.
UNSIGNED SMALLINT numbers also require 2 bytes but hold values in
the range 0 to 65,535. This doubles the range of positive values as compared
with SMALLINT.
The INTEGER data type requires 4 bytes of storage and holds values in the
range 2,147,483,648 to 2,147,483,647. This data type is commonly used for
DEFAULT AUTOINCREMENT primary keys for large tables.
UNSIGNED INTEGER numbers also require 4 bytes but hold values in the
range 0 to 4,294,967,295. This is an even better choice for large positive pri-
mary keys.
The BIGINT data type is the largest binary integer, requiring 8 bytes of
storage and holding values in the range 9,223,372,036,854,775,808 to
9,223,372,036,854,775,807. This is often the data type of choice for DEFAULT
GLOBAL AUTOINCREMENT primary keys because there is plenty of room
for many large partitions.
UNSIGNED BIGINT numbers also require 8 bytes but hold values in the
range 0 to 18,446,744,073,709,551,615. Like the other UNSIGNED integer
types this one doubles the range of positive values.

Tip: Some programming languages use different names for these data types.
SQL Anywhere 9s SMALLINT may be called short integer or just integer.
INTEGER may be called long integer, long, or even integer. BIGINT may
not be available, so you must use some variation of an exact decimal type.

Vous aimerez peut-être aussi