SQL Server REAL Data Type
SQL Server REAL is an approximate floating-point type that occupies 4 bytes and provides about 7 significant decimal digits. It is a synonym for FLOAT(24); see Microsoft’s FLOAT and REAL documentation.
Syntax
In SQL Server, the syntax for the REAL data type is as follows:
REAL
Usage
The REAL data type is suitable for storing data that needs to represent larger or smaller numerical values, such as scientific or engineering calculations.
REAL and FLOAT(1) through FLOAT(24) use the same 4-byte, approximately 7-digit representation. FLOAT(25) through FLOAT(53) use 8 bytes and provide about 15 digits. Both types store approximate values; use DECIMAL or NUMERIC when exact decimal behavior is required.
Examples
Here are two examples using the REAL data type.
Creating a table:
CREATE TABLE Temperature (
Date DATE,
Temperature REAL
);
Inserting data:
INSERT INTO Temperature (Date, Temperature)
VALUES ('2022-01-01', 25.4),
('2022-01-02', 23.9),
('2022-01-03', 24.8),
('2022-01-04', 21.5),
('2022-01-05', 20.6);
Querying data:
SELECT *
FROM Temperature;
Results:
| Date | Temperature |
|---|---|
| 2022-01-01 | 25.4 |
| 2022-01-02 | 23.9 |
| 2022-01-03 | 24.8 |
| 2022-01-04 | 21.5 |
| 2022-01-05 | 20.6 |
Calculating the average temperature:
SELECT AVG(Temperature) AS AverageTemperature
FROM Temperature;
Results:
| AverageTemperature |
|---|
| 23.24 |
Conclusion
REAL is a synonym for FLOAT(24): a 4-byte approximate type with about 7 significant decimal digits. For higher floating-point precision, see FLOAT; for exact decimal values, see DECIMAL or NUMERIC.