Before we continue, let's review what we already know about numbers. Integers are expressed in the following way:
-27, etc. Floating-point numbers are expressed with a dot (
-401.238, etc. Please note that in some languages, you use a comma instead of a dot, but not in T-SQL! For example,
12,45 is incorrect.
In SQL Server (and in most programming languages) there are three kinds of numbers:
- integer (int): stores integers or "normal" numbers (e.g., -5, 0, 5, 42),
- floating-point (float): stores floating-point numbers by approximating them in binary,
- decimal: stores floating-point numbers without approximation, as their exact numerical representation.
We'll discuss some of the differences between SQL Server's numeric data types. Of course, you can use the four basic mathematical operations (add
*, and divide
/) with actual numbers in T-SQL. You can also use columns and constant numbers together. Take a look at the example below:
HP / 4 AS QuarterHP