- 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 datatype is should I use to set a column for 5-star rating?
You can use ENUM datatype for this. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserRating ENUM('1','2','3','4','5') ); Query OK, 0 rows affected (0.54 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(UserRating) values('5'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(UserRating) values('3'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(UserRating) values('1'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(UserRating) values('3'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(UserRating) values('4'); Query OK, 1 row affected (0.18 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+----+------------+ | Id | UserRating | +----+------------+ | 1 | 5 | | 2 | 3 | | 3 | 1 | | 4 | 3 | | 5 | 4 | +----+------------+ 5 rows in set (0.00 sec)
- Related Articles
- Which datatype should I use for flag in MySQL?
- Which MySQL Datatype should be used for storing BloodType?
- What type of datatype should I use (MySQL) with a mix of string and number?
- How to create a simple "star rating" look with CSS?
- Should I use , , or for SVG files?
- For timestamp, which datatype is used in MySQL?
- Should I use PyCharm for Programming in Python?
- MySQL isn’t inserting binary data properly? Which datatype should be used?
- Why should I use Hubspot?
- PHP string cast vs strval function, which one should I use?
- How do I alter table column datatype on more than 1 column at a time in MySql?
- Change a MySQL Column datatype from text to timestamp?
- How do I set the default value for a column in MySQL?
- How to set NOW() as default value for datetime datatype in MySQL?
- When Should I use Selenium Grid?

Advertisements