
The conversion of decimal or numeric value to a floating-point number or float may lead to a loss of precision. Converting Decimal and Numeric DataĪ constant with a decimal point in SQL statements is automatically converted into a numeric data value. For example: if we insert 878.00009 into a FLOAT(7,4) column, the approximate result is 878.0001. The exponent value is also a positive value that is used to define the number of digits to the right of the decimal point. The salary column is a numeric data type with a scale of 2 (two digits in the right place of the decimal) and a precision of 8 (i.e., the salary can be an eight-digit number). Suppose we want to create an employee table with three columns, namely account name, account number, and salary. Let us take the example of a company database to understand the syntax better. Else, the right decimal places are considered. If the number is negative, the left decimal places are considered. Scale or s is also an integer value (s must be a value from 0 top, and its default value is 0) that is used to define the maximum number of decimal places allowed to the right or left of the decimal point. So, the number stored in the specified column can be base-2 or base-10. The radix or base of the precision digit is either decimal (base-10) or binary (base-2). Its default value is 18, and it can be avoided. Precision or p is an integer representing the total number of allowed digits in the specified column. Here, numeric is a data type that takes 5-17 bytes storage. Below is the list of data types that are included under the numeric data type in SQL: The numeric data type in SQL is one of the most widely used data types to store numeric values. We can broadly categorize these data types into three main categories: string, numeric, and date and time. We can use these data types to define the data of our rows and columns.

MySQL is a commonly known DBMS that supports a wide range of data types such as char, varchar, binary, text, boolean, bit, integer, float, date, etc. A SQL query (called query in short) is used to fetch the records from tables of a database. Before we start manipulating the data, we need to first insert the data into the tables as well. SQL or Structured Query Language is used to manipulate and communicate with the data stored as tables in the database. SQL Numeric Data Typeīefore learning about numeric data types in SQL, let us first briefly learn about SQL and Database Management Systems.

The integer data type consists of SMALLINT, INTEGER, TINYINT, and BIGINT. The integer data type is used to store whole numbers (numbers without the decimal point or simply nondecimal numbers). Numbers in SQL can be either exact ( NUMERIC, DECIMAL, INTEGER, BIGINT, and SMALL INT) or approximate ( DOUBLE PRECISION, FLOAT, and REAL). The numeric data type in SQL is one of the most widely used data types to store numeric-like values.
