How willl I set the default value for the enum datatype MySQL name to "No"?

I have a field in my Mysql table whose values ​​('Yes', 'No'), which are an enumeration data type.

Here I want to set its default value to No. But when I set it to No, it doesn’t matter. How do i do this?

+6
source share
3 answers
CREATE TABLE enum_test ( enum_fld ENUM('Yes', 'No') DEFAULT 'No' ); 

or something like that

+7
source

If an ENUM column is declared to allow NULL, NULL is the legal value for the column and the default is NULL. If an ENUM column is declared NOTNULL, its default value is the first element in the list of valid values.

So something like this will help:

 CREATE TABLE enum_test (enum_fld ENUM ('No', 'Yes')); 

https://dev.mysql.com/doc/refman/5.0/en/enum.html

+6
source
 DROP TABLE IF EXISTS test_enum; Query OK, 0 rows affected, 1 warning (0.00 sec) CREATE TABLE test_enum(ID INT , Name CHAR(30), IsActive ENUM('Yes','No') DEFAULT 'No'); Query OK, 0 rows affected (0.29 sec) INSERT INTO test_enum(ID,Name) VALUES(1,'Abdul'); Query OK, 1 row affected (0.00 sec) SELECT * FROM test_enum; +------+-------+----------+ | ID | Name | IsActive | +------+-------+----------+ | 1 | Abdul | No | +------+-------+----------+ 1 row in set (0.00 sec) INSERT INTO test_enum(ID,Name,IsActive) VALUES(1,'Abdul','Yes'); Query OK, 1 row affected (0.00 sec) SELECT * FROM test_enum; +------+-------+----------+ | ID | Name | IsActive | +------+-------+----------+ | 1 | Abdul | No | | 1 | Abdul | Yes | +------+-------+----------+ 2 rows in set (0.00 sec) 
+1
source

All Articles