<< Previous - SQL Syntax
Next SQL Create Database>>
Data type is used to represent the kind of data that database of tables can hold.
SQL data types
- Exact Numeric data type
- Approximate Numeric data type
- Character String data type
- Date and Time data type
- Binary data type
- Other data type
SQL - Exact Numeric Data Type - INTEGER
Keyword | Range | Storage size |
---|
bit(size) | 0,1 or NULL | 1 bit |
tinyint | 0 to 255 | 1 bytes |
smallint | -32,768 to 32,767 | 2 bytes |
int(size) | -2,147,483,648 to 2,147,483,647 | 4 bytes |
bigint | -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807) | 8 bytes |
decimal(p,[s]) | -10^38+1 to +10^38-1 | 5-17 bytes |
numeric(p,[s]) | -10^38+1 to +10^38-1 | 5-17 bytes |
Smallmoney | -214,748.3648 to +214,748.3647 | 4 bytes |
Money | -922,337,203,685,477.5808 to +922,337,203,685,477.5807 | 8 bytes |
SQL - Approximate Numeric Data Types - float and real
Keyword | Range | Storage size |
---|
float | -1.79E+308 to 1.79E+308 | 4-8 bytes |
real | -3.40E+38 to 3.40E+38 | 4 bytes |
SQL Data Type - Character
Datatype | Description |
---|
char(n) | n=1 to 8000 fixed length non- unicode character. |
varchar(n/max) | n= 1 to 8000 variable length non unicod characters. max= 2E+31 variable length nonunicode characters. |
text(n) | n=1 to 2,147,483,647 (2GB) variable length unicode characters. |
Unicode Character String Data Types
Datatype | Description |
---|
nchar(n) | n=1 to 4000 fixed length unicode characters string. |
nvarchar(n/max) | n= 1 to 4000 variable length unicod characters string. max= 2E+31 variable length unicode charaters string. |
ntext | Variable length unicode characters string with maximum length of 1,073,741,823 characters. |
SQL Binary Data Types
Datatype | Description |
---|
binary | Fixed length binary data with maximum length of 8000 bytes |
varbinary | Variable length binary data with maximum length of 8000 bytes |
varbinary(max) | Variable length binary data with maximum length of 2E+31 bytes(SQL server 2005 only) |
image | Variable length binary data with maximum length of 2,147,483,64bytes |
SQL Date and Time Data Types
Datatype | Description | Size |
---|
datetime | Datetime used to store both date and time with accuracy of 3.33 milliseconds. Format: YYYY-MM-DD hh:mm:ss. Date range from Jan 1, 1753 to Dec 31,9999 and time range from 00:00:00 to 23:59:59.997 | 8 bytes |
smalldatetime | Date range from Jan 1, 1900 to Jun 30 ,2079 and time range from 00:00:00 to 23:59:59 | 4 bytes |
date | Date in SQL stores only date and its range from Jan 1, 001 to Dec 31, 9999 Format:YYYY-MM-DD | 3 bytes |
time | Time in SQL Stores only time with accuracy of 100 nanoseconds. Its range from 00:00:0000000 to 23:59:59.9999999 Format:hh:mm:ss | 3 to 5 |
timestamp | timestamp specifies the date, time and timezone information |
<< Previous - SQL Syntax
Next SQL Create Database >>