如何为行插入和更新多个枚举值?

时间:2021-12-15 15:41:41

As I read this answer, I guess if it possible to insert and update multiple ENUM "checked" values for a row, with MySQL.

当我读到这个答案时,我猜是否可以使用MySQL插入和更新一行的多个ENUM“已检查”值。

Entity example:

TABLE
id INT auto_increment
day_list ENUM ('1','2','3,'4','5,'6','7')
gender ENUM ('m','f')

I tried the following (to specify that the week end is checked and the two genders too) :

我尝试了以下(指定周末检查和两个性别):

INSERT INTO TABLE (day_list,gender) VALUE ('{6,7}','{m,f}')

It doesn't return any error, and insert correctly the record, but the day_list and the gender fields are empty.

它不会返回任何错误,并正确插入记录,但day_list和gender字段为空。

So, it seems that it doesn't work with mySQL. And it doesn't seem to be possible in phpMyAdmin (3.2.0), as the values are checked by radio buttons (and not checkboxes).

所以,它似乎不适用于mySQL。它似乎不可能在phpMyAdmin(3.2.0)中,因为值通过单选按钮(而不是复选框)进行检查。

Any idea on how to make it work ? Or another solution to record and select those checked days without LIKE request and without association entity (like TABLE_DAYS and TABLE_GENDER) ?

有关如何使其工作的任何想法?或者另一种解决方案是记录和选择没有LIKE请求且没有关联实体的那些检查日(如TABLE_DAYS和TABLE_GENDER)?

1 个解决方案

#1


3  

In MySQL, an ENUM type field can accept only one value.

在MySQL中,ENUM类型字段只能接受一个值。

After doing some searches in phpMyAdmin, it seems that a SET type will do the job.

在phpMyAdmin中进行一些搜索后,似乎SET类型将完成这项工作。

So the entity :

所以实体:

TABLE
id INT auto_increment
day_list SET ('1','2','3,'4','5,'6','7')
gender SET ('m','f')

How to insert :

如何插入:

INSERT INTO TABLE (day_list,gender) VALUE ('6,7','m,f')

And about searching for values :

关于搜索价值:

  • If values are integers : IN can work if data is ordered.
  • 如果值是整数:如果订购数据,IN可以工作。

  • If values are not integers : FIND_IN_SET is required and search data doesn't need to be ordered.
  • 如果值不是整数:需要FIND_IN_SET并且不需要订购搜索数据。

Limitation : SET type only accept 64 members, for more a foreign association entity will be required.

限制:SET类型只接受64个成员,因为需要更多的外国协会实体。

#1


3  

In MySQL, an ENUM type field can accept only one value.

在MySQL中,ENUM类型字段只能接受一个值。

After doing some searches in phpMyAdmin, it seems that a SET type will do the job.

在phpMyAdmin中进行一些搜索后,似乎SET类型将完成这项工作。

So the entity :

所以实体:

TABLE
id INT auto_increment
day_list SET ('1','2','3,'4','5,'6','7')
gender SET ('m','f')

How to insert :

如何插入:

INSERT INTO TABLE (day_list,gender) VALUE ('6,7','m,f')

And about searching for values :

关于搜索价值:

  • If values are integers : IN can work if data is ordered.
  • 如果值是整数:如果订购数据,IN可以工作。

  • If values are not integers : FIND_IN_SET is required and search data doesn't need to be ordered.
  • 如果值不是整数:需要FIND_IN_SET并且不需要订购搜索数据。

Limitation : SET type only accept 64 members, for more a foreign association entity will be required.

限制:SET类型只接受64个成员,因为需要更多的外国协会实体。