SPS Home > Dgreath > RDBMS > Datatypes |
RELATIONAL DATABASE DATATYPES |
---|
The following table presents the various datatypes, minimum and maximum values, and physical size in bytes: |
Relational Database System Datatypes | |||||
---|---|---|---|---|---|
CATEGORY | SYSTEM DATATYPE |
MIN VALUE | MAX VALUE | SIZE BYTES |
DESCRIPTION |
EXACT NUMERIC |
TINYINT |
0 | 255 | 1 | Unsigned integer |
SMALLINT |
-32,768 | +32,768 | 2 | Signed integer | |
INT |
-2,147,483,648 | +2,147,483,647 | 4 | Signed integer | |
BIGINT |
-2^63 | +2^63 - 1 | 8 | Signed integer | |
NUMERIC(n,m) |
-10^38 | +10^38 - 1 | 5 - 17 | Fixed precision and scale numeric value | |
MONEY |
-2^63 | +2^63 - 1 | 8 | Monetary value | |
SMALLMONEY |
-214,768.3648 | +214,748.3647 | 4 | Monetary value | |
BIT |
0 | 1 | 1 | Boolean value | |
APPROX. NUMERIC |
FLOAT |
-1.79^308 | +1.79^308 | 8 | Large floating point numbers |
REAL |
-3.40^38 | +3.40^38 | 4 | Small floating point numbers | |
DATE & TIME |
DATETIME |
1/1/1753 | 12/31/9999 | 8 | Long dates |
SMALLDATETIME |
1/1/1900 | 6/6/2079 | 4 | Short dates | |
CHARACTER STRINGS |
CHAR(s) |
1 | 8,000 characters | Note 1 | Fixed length character |
VARCHAR(s) |
1 | 8,000 characters | Notes 1,4 | Variable length character | |
NCHAR(s) |
1 | 4,000 characters | Notes 1, 3 | Fixed length unicode character | |
NVARCHAR(s) |
1 | 4,000 characters | Notes 1,3,4 | Variable length unicode character | |
TEXT |
1 | 2GB | Note 2 | Large block character | |
NTEXT |
1 | 1GB | Notes 2, 3 | Large block unicode character | |
BINARY STRINGS |
BINARY(t) |
1 | 8,000 bytes | Note 1 | Fixed length binary data |
VARBINARY(t) |
1 | 8,000 bytes | Note 1, 4 | Variable length binary data | |
IMAGE |
1 | 2 GB | Note 2 | Binary Large Object (BLOB) | |
SPECIAL | SQL_VARIANT |
Note 5 | The universal datatype | ||
TABLE |
Note 6 | Temporary storage of a result set | |||
ROWVERSION |
8 | Binary data to ensure row uniqueness | |||
UNIQUEIDENTIFIER |
16 | Globally Unique Identifier (GUID) | |||
Notes:
n = number of total digits (min 1, max 38) |
|||||
Definition and deletion of user datatypes: To avoid the possibility of data inconsistency, users can create standardized datatypes for things like zipcodes, phone numbers, social security numbers, and the like. To do so, use the stored procedure "sp_addtype" and specify the identity, datatype and length, and nullability ( NULL or NOT NULL )
as follows:
USE dbname Note: the single quotes around the datatype specification are required. Once a datatype has been created, it can be used in the same way as the system datatypes. User datatypes can be deleted using the "sp_droptype" stored procedure as follows: USE dbname |