Home > Article > Daily Programming > What does enum mean in mysql
ENUM is an enumeration data type in MySQL that is used to limit the range of stored values. It works by storing a predefined list of values, ensuring data integrity, space efficiency, and performance. Creating a table with ENUM columns requires the use of the CREATE TABLE statement, and data can then be inserted and updated using predefined values. ENUM columns can be used in queries and comparisons to ensure that the data fits within the desired range.
The meaning of ENUM in MySQL
ENUM is a data type in MySQL, used to store a limited number of Predefined value. It is similar to the string data type, but it limits the range of values that can be stored.
How ENUM works
The ENUM column defines a predefined list of values from which you can only choose from when inserting data. The values are stored in the database in comma separated form.
Advantages of ENUM
Create ENUM columns
Use the CREATE TABLE statement to create a table with ENUM columns:
<code class="sql">CREATE TABLE my_table ( id INT NOT NULL AUTO_INCREMENT, status ENUM('active', 'inactive') NOT NULL, PRIMARY KEY (id) );</code>
In this example, status
The column will only be able to store the values 'active' or 'inactive'.
Inserting and updating ENUM values
When inserting data into an ENUM column, you must use one of the predefined values:
<code class="sql">INSERT INTO my_table (status) VALUES ('active'); UPDATE my_table SET status = 'inactive' WHERE id = 1;</code>
Use ENUM Column
You can use ENUM columns in queries and comparisons as follows:
<code class="sql">SELECT * FROM my_table WHERE status = 'active'; IF (status = 'active') { # 执行操作 }</code>
The above is the detailed content of What does enum mean in mysql. For more information, please follow other related articles on the PHP Chinese website!