Numeric Data Type
The Numeric data type is used to represent a number with fixed precision and fixed scale. This means, there is a defined precision for numeric data type such that if we try to store a number that is out of bounds, the numeric data type will return an error.
Syntax:
NUMERIC(precision, scale)
Numeric Data Type Example
-- Create the table
CREATE TABLE STUDENT(
Name VARCHAR(20),
Result NUMERIC(5,2)
);
-- Insert sample data
INSERT INTO STUDENT(Name, Result) VALUES ('John', 98.75);
INSERT INTO STUDENT(Name, Result) VALUES ('Alice', 87.50);
Output:
Explanation: The SQL script creates a table named “STUDENT” with columns “Name” and “Result” of data type NUMERIC(5,2), allowing for fixed precision numbers with 5 total digits and 2 decimal places. Sample data is inserted with the names “John” and “Alice” along with their corresponding results, where precision is enforced.
What is the Difference Between Numeric, Float, and Decimal in SQL server?
The SQL Server has a variety of data types to store data. These data types can accompany several forms like string, integer, double, date, time, etc. Therefore selecting the appropriate data structure is crucial for maintaining the data accuracy and optimizing the system’s performance.
This article delves into the fundamentals of three crucial data types: Numeric, Float, and Decimal.
Contact Us