timevova.blogg.se

Correct use of enum in mysql
Correct use of enum in mysql












correct use of enum in mysql

ENUM‘s are sorted by their acceptable values in that order they were implemented during table creation. | fruit | enum ( 'Pear', 'Cherry', 'Orange', 'Banana', 'Pineapple', 'Grape', 'Kiwi', 'Apple', 'Fig' ) In similar fashion, we have another ‘fruit’ table but this one uses a VARCHAR data type to store the fruit name: | fruit | enum ( 'Pear', 'Cherry', 'Orange', 'Banana', 'Pineapple', 'Grape', 'Kiwi', 'Apple', 'Fig' ) | YES | | NULL | | | Field | Type | Null | Key | Default | Extra | I’ll leave you to refer to that resource for additional specific details if interested.įor this oversimplified example, we are only accepting book genre types from the 3 values listed as shown for the genre column in the book_club table definition. Exact storage size information is located in section 11.8 Data Type Storage Requirements. The official documentation from section 11.4.4 The ENUM Type, mentions that there are storage benefits from using ENUM‘s. When you need a string data type column to only store allowable values from a preferred list, this is one area where an ENUM is a strong candidate. In truth, any of the other MySQL string data types (e.g., VARCHAR and TEXT) could have been used for this example but herein lies a potential use case for the ENUM. (Note: This example would be stored better with a normalized schema but I am only interested in covering the ENUM data type so normalization practices are not covered in this blog post.) Suppose I have this simple table representing books shared in a book club for 3 specific genres: ‘Western’, ‘Fantasy’, and ‘Military’.

correct use of enum in mysql

Xubuntu Linux 16.04.5 LTS (Xenial Xerus).It by no means depicts actual data belonging to or being used by any party or organization. Note: All data, names or naming found within the database presented in this post, are strictly used for practice, learning, instruction, and testing purposes. Photo by Glenn Carstens-Peters on Unsplash














Correct use of enum in mysql