Introduction

In Microsoft SQL Server (MSSQL), the DECIMAL, FLOAT, and NUMERIC data types are used to store numerical values, but they have differences in terms of precision, storage, and behavior. Here's a comparison of these data types in MSSQL:

1. DECIMAL

2. FLOAT

CREATE TABLE Temperature (
    City VARCHAR(50),
    Celsius FLOAT
);

INSERT INTO Temperature (City, Celsius) VALUES ('New York', 20.5);
INSERT INTO Temperature (City, Celsius) VALUES ('Los Angeles', 25.75);

SELECT * FROM Temperature;

In this example, the Celsius column stores floating-point values, which might have slight inaccuracies due to the floating-point representation. It's suitable for scientific or engineering calculations where precision is less important than a wide range of values.

3. NUMERIC

CREATE TABLE Products (
    ProductID INT,
    Price NUMERIC(8, 3)
);

INSERT INTO Products (ProductID, Price) VALUES (101, 12.345);
INSERT INTO Products (ProductID, Price) VALUES (102, 98.765);

SELECT * FROM Products;

Like the DECIMAL example, the Price column stores exact decimal values with a total of 8 digits, including 3 decimal places.

Remember that while DECIMAL and NUMERIC are often interchangeable, it's important to consult the documentation of SQL Server for any nuances or differences in behavior.