- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Which MySQL type is most suitable for “price” column?
The best type for price column should be DECIMAL. The type DECIMAL stores the value precisely.
For Example - DECIMAL(10,2) can be used to store price value. It means the total digit will be 10 and two digits will be after decimal point.
To understand the type DECIMAL, 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)
Display all records which we have inserted above. The 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)
- Related Articles
- Which MySQL data type is used for long decimal?
- MySQL index on column of int type?
- The most suitable material for the preparation of handles of cooking utensils ispolythenePVCnylonbakelite
- How to update a MySQL date type column?
- What is the data type for unix_timestamp in MySQL?
- Count top 10 most occurring values in a column in MySQL?
- MySQL Select displaying Data type in a separate column?
- How to extract column name and type from MySQL?
- What role data type plays when I insert an empty string into a MySQL column which is declared as NOT NULL?
- How to display two different sums of the same price from column Amount in MySQL?
- MySQL query to fetch column length declared with BLOB type
- Set default value to a JSON type column in MySQL?
- MySQL query to sum the Product Price values from similar columns for same customers and display the result in the same column
- Wildcards in column name for MySQL?
- MySQL database field type for search query?

Advertisements