The best type for the price column should be DECIMAL. The DECIMAL type stores values exactly.
For example- DECIMAL(10,2) can be used to store price values. This means that the total number of digits is 10, with two digits after the decimal point.
To understand the DECIMAL type, let us create a table.
mysql> create table PriceDemo −> ( −> ProductPrice DECIMAL(10,2) −> ); Query OK, 0 rows affected (0.60 sec)
Now insert some records in the table in the form of price. The query to insert records is as follows -
mysql> insert into PriceDemo values(12345.67); Query OK, 1 row affected (0.12 sec) mysql> insert into PriceDemo values(99999999.67); Query OK, 1 row affected (0.17 sec) mysql> insert into PriceDemo values(123456.67); Query OK, 1 row affected (0.17 sec) mysql> insert into PriceDemo values(4444444.50); Query OK, 1 row affected (0.18 sec)
displays all the records we inserted above. Query to display all records −
mysql> select *from PriceDemo;
The following is the output -
+--------------+ | ProductPrice | +--------------+ | 12345.67 | | 99999999.67 | | 123456.67 | | 4444444.50 | +--------------+ 4 rows in set (0.00 sec)
The above is the detailed content of Which MySQL type is best for the "price" column?. For more information, please follow other related articles on the PHP Chinese website!