您可以为此使用ENUM数据类型。 让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserRating ENUM('1','2','3','4','5') );
使用插入命令在表中插入记录-
mysql> insert into DemoTable(UserRating) values('5'); mysql> insert into DemoTable(UserRating) values('3'); mysql> insert into DemoTable(UserRating) values('1'); mysql> insert into DemoTable(UserRating) values('3'); mysql> insert into DemoTable(UserRating) values('4');
使用选择命令显示表中的记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+------------+ | Id | UserRating | +----+------------+ | 1 | 5 | | 2 | 3 | | 3 | 1 | | 4 | 3 | | 5 | 4 | +----+------------+ 5 rows in set (0.00 sec)