SQL
SQL Server data types
Numeric data types:
Precision: Total number of digits
Scale: Number of digits to the right of the decimal
| Data type | Bytes |
|---|---|
| bit | 1 |
| tiny int | 1 |
| small int | 2 |
| int | 4 |
| big int | 8 |
| numeric(precision,scale) | depends on precision |
| decimal(precision,scale) | depends on precision |
| float(n) | depends on n |
| real | 4 |
| small money | 4 |
| money | 8 |
Char and varchar data types:
Char is fixed length and varchar is variable length
| Data type | Range |
|---|---|
| char(n) | 1 to 8000 |
| varchar(n) | 1 to 8000 |
| varchar(max) | 2^31-1 |
Unicode data types: supports all languages
| Data type | Range |
|---|---|
| nchar(n) | 1 to 4000 |
| nvarchar(n) | 1 to 4000 |
| nvarchar(max) | 2^30-1 |
Date data types:
| Data type | Bytes | Description |
|---|---|---|
| Date | 3 | |
| small datetime | 4 | Rounded to nearest minute |
| datetime | 8 | has fractional seconds |
| datetime2 | 6 to 8 | Precise to nanoseconds |
| datetimeoffset | 10 | Stores offset between local time and UTC |
| time | 5 |
Binary data types:
| Data type | Range | Description |
|---|---|---|
| binary | 0 to 8000 | stores images, text etc |
| varbinary | 0 to 8000 | stores images, text etc |
Other data types:
| Data type | Description |
|---|---|
| timestamp | It is an autogenerated number |
| uniqueidentifier | It is a 16 byte GUID |
| sql_variant | Stores values of various data types |
| cursor | Used for variables |
| xml | Used to store xml data |