Numeric Data Types
Numeric data types are used to store numerical values. SQL Server provides several numeric data types, each with a different range of values it can store. Choosing the right data type is important for data integrity and performance.
Data Type Overview
The following table provides a summary of the most common numeric data types in SQL Server:
| Data Type | Size | Precision | Range | Notes |
|---|---|---|---|---|
bit |
1 | -1 to 1 | Stores whole numbers, either 0 or 1. | |
tinyint |
1 | -128 to 127 | Small integer. | |
smallint |
2 | -32768 to 32767 | Smaller integer. | |
int |
2 | -2147483648 to 2147483647 | Standard integer. | |
bigint |
8 | -9223372036854775808 to 9223372036854775807 | Larger integer. | |
decimal |
variable | variable | Supports precise decimal values. | |
money |
variable | variable | Stores monetary values. | |
numeric |
variable | variable | Similar to decimal, but with different syntax. |
Note: The exact range and precision of a data type may vary depending on the SQL Server version and configuration.
Precision and Scale
Precision and scale are important concepts when working with numeric data types, especially with the decimal and numeric data types. Precision refers to the total number of digits that can be stored, while scale refers to the number of digits to the right of the decimal point.
Example: A decimal(10, 2) data type can store a number with a total of 10 digits, with 2 digits to the right of the decimal point.
More detailed information on precision and scale can be found in the Precision and Scale documentation.