开发者

how can I store a set of values in SQL table

开发者 https://www.devze.com 2023-01-08 13:13 出处:网络
I need to store a set of values e.g. A, B, C under say country column of a SQL ta开发者_运维技巧ble. Coould you let me know if there is any data type that is able to storea set of values in a SQL tabl

I need to store a set of values e.g. A, B, C under say country column of a SQL ta开发者_运维技巧ble. Coould you let me know if there is any data type that is able to store a set of values in a SQL table column?

Thanks in advance.


To store a set, you would normally create a second table with a foreign key relation.

MySQL also has some functions to store a comma-separated list in a column, like find_in_set. This is considered bad form, though you might choose it for a quick one-time hack.

EDIT: For some reason Bakkal deleted his answer. His answer was new to me and I thought it was rather interesting, so I'll copy it here:

https://dev.mysql.com/doc/refman/5.7/en/set.html

This allows you to store a small set (less than 65 items) in a column.


That's probably bad database design.

From what I can see you should create a new table OR if you know you'll only have up to 3 countries, have 3 separate columns

0

精彩评论

暂无评论...
验证码 换一张
取 消