MySQL 29 - SET Data Type

submitted by mkenny400 on 03/20/18 1

The SET data type is very similar to ENUM, so be sure to watch the previous video. The easiest way to explain set is to compare it ENUM. An enumeration allows you to select one item from a list of items. SET is different in that it allows you to select multiple items. Literally, a set of options. Another difference is that the number of available options you can have for a SET column is much lower, 64 compared to ENUM which can support thousands. Once again, the usefulness of SET can be thrown into question because you can do the same thing with database design. For example, if we have a set of available values and you allow the user of the database to SELECT multiple, the chances are it is a many-to-many relationship, which we've discussed how to design those in a previous video. That being said, if you decide to use the SET data type, the way you declare it is exactly the same as the ENUM type. An example may be the category of an item on a bidding website. We may sell something like an old car and we would like the categories to be transportation, automobiles, and antiques. To create a column with these options, we would put every possible category in the data type declaration as comma separated strings: SET('transportation', 'automobiles', 'antiques'….). The difference in how we use ENUM and SET shows up when we INSERT data. The way you INSERT data is you put all of the categories separated by commas inside of quotes. For example: INSERT INTO listings VALUES ('transportation, automobiles, antiques'); You are going to have to avoid any values that have commas in them because it will confuse MySQL. You will also want to know that if you insert duplicate values in the same row they will be removed, and when you SELECT the data back it will be sorted in the order that the SET was declared. The last thing you will need to consider is your character set. Character sets have what is known as a collation, which deals with case sensitivity. The collation will be taken into account when INSERTING data. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×