Home > Database > Mysql Tutorial > body text

Which MySQL type is best for the 'price' column?

PHPz
Release: 2023-09-09 17:01:12
forward
522 people have browsed it

哪种 MySQL 类型最适合“价格”列?

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)
Copy after login

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)
Copy after login

displays all the records we inserted above. Query to display all records −

mysql> select *from PriceDemo;
Copy after login

The following is the output -

+--------------+
| ProductPrice |
+--------------+
|     12345.67 |
|  99999999.67 |
|    123456.67 |
|   4444444.50 |
+--------------+
4 rows in set (0.00 sec)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!