MySQL 28 - ENUM

submitted by mkenny400 on 03/20/18 1

The next character type we are going to talk about is called ENUM. ENUM is short for enumeration. What is an enumeration? In computer science an enumeration is a list of values where you can select one. With this data type, we can give a list of available options for a column and the user will have to select from that list. Remember back when I talked about integrity? This was something I should have added, but did not think of it. It allows us to force certain data into a column, and each row can only have one of the available values. This is in contrast to another data type that works similarly which we will talk about in an upcoming video. The special thing about an enumeration is that everything is secretly stored as a number. For example, we can have a bidding website where we can select the condition of a product as new, very good, good, etc. Now, there are numerous ways we can do this in a database… ENUM is just one. Each possible value is going to be given a number. You could say that this number is the index of the enum. This is a different kind of index than a table index. New - 1 Very good - 2 Good - 3 Used - 4 Bad - 5 Note that the indexing starts with one. This is actually an odd thing when compared to most indexing. There actually is something at index 0, and that is an empty string. This is the value that will be given when a user inserts an invalid value. Another option is to not put anything at all, and in that case the index will be null. What is the benefit of storing these as numbers? One benefit is to reduce space. That's because storing these numbers is only going to take one byte per row. Not super helpful though because we could just reference an ID from another table and we wouldn't be redundantly storing a string. I don't think the reasons to use ENUM outweigh the downsides of using ENUM, which is ultimately added complexity and issues if we ever want to move our database to another RDBMDS. When you do want to use a ENUM, I recommend that you keep the available options low. When we add this data type to the CREATE TABLE statement, it would just look like ENUM('New', 'Very Good', 'Good', 'Used', 'Bad'). When actually inserting data, it is not going to be any different than inserting a normal string. In the next video we will be talking about the SET data type. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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)

×