tags:

views:

62

answers:

2

Hi All,

I need to store a set of values e.g. A, B, C under say country column of a SQL table. 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.

+3  A: 

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:

http://dev.mysql.com/tech-resources/articles/mysql-set-datatype.html

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

Andomar
+2  A: 

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

NullUserException
We can't comment anything good and bad without knowing the end user requirement. What he/she will do if his boss is thinking odf the same. If its requirement, either good or bad try to use the same design as far as possible. As far as i know not all situation are as per us, so insteading showing the guys , our own way, i think we should help them in moving their own required way with awaring them pro's and cons too.
Amit Ranjan
That's why I said *probably* bad
NullUserException
-1 to Amit's comment (it's a shame we can't *actually* downrate comments) - the business domain is the source of the data requirements, but it's up to us as developers to implement it. Repeating groups across a row breaks 1NF and should be avoided where possible.
Mark Bannister