Should I use MySQL enum or tinyint for fields having values 1 and 0?

MySQLMySQLi Database

For 0 and 1 values, use TINYINT. Let us first create a table −

mysql> create table DemoTable
   -> (
   -> IsMarried tinyint
   -> );
Query OK, 0 rows affected (0.94 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(1);
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values(0);
Query OK, 1 row affected (0.13 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable;

This will produce the following output −

+-----------+
| IsMarried |
+-----------+
|         1 |
|         0 |
+-----------+
2 rows in set (0.00 sec)
raja
Published on 18-Dec-2019 06:05:22
Advertisements