Database Reference
In-Depth Information
SET
A set is a collection of things that are unique, the order of which is not important. For
instance, the following is a set:
Spoon
Fork
Knife
That set is exactly the same as the following set:
Knife
Fork
Spoon
It does not matter if the elements of the set contain the items in a different order; if all of
the elements are the same then the set is the same, irrespective of the order. However, the
following is not a set as it contains a duplicate:
Knife
Spoon
Fork
Knife
The SET datatype in MySQL is used for storing elements of a set in each row of the table.
The elements of the set are defined at the time that the column is declared and are stored as
strings in the declaration. You can have a maximum of 64 elements in a MySQL set. To store
occurrences of the set above you would use the following:
columnname SET(“Knife”,“Fork”,“Spoon”)
What this datatype actually does, is to allow each row of the column to store the follow-
ing values:
“”
“Knife”
“Fork”
“Fork,Knife”
“Spoon,Fork,Knife”
“Spoon” etc.
The first item on the list above contains no elements, it is referred to as “the empty set”
and it is still a valid element of the defined set. If you try and insert a string that is not
within the set definition, then that is ignored. If you are adding more than one element to a
set, then you should include them all in the same string, separated by commas.
SET is useful for storing the responses from an online questionnaire or anything that
requires selections from a predefined list. This is useful as although when you retrieve
Search WWH ::




Custom Search