

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Which datatype should I use for flag in MySQL?
- Which MySQL Datatype should be used for storing BloodType?
- For timestamp, which datatype is used in MySQL?
- What type of datatype should I use (MySQL) with a mix of string and number?
- PHP string cast vs strval function, which one should I use?
- How to create a simple "star rating" look with CSS?
- Why should I use Hubspot?
- When Should I use Selenium Grid?
- Which one should I use? The datetime or timestamp data type in MySQL?
- MySQL isn’t inserting binary data properly? Which datatype should be used?
- Give 5 reasons why should I quit non-veg and be a vegan?
- When should I use a composite index in MySQL?
- When should I use MySQL compressed protocol?
- What is a smart pointer and when should I use it in C++?
- How should I display MySQL database that is currently in use?
Advertisements