Home  >  Article  >  Database  >  What is the smallest one-digit data type in MySQL?

What is the smallest one-digit data type in MySQL?

PHPz
PHPzforward
2023-09-02 12:05:02676browse

MySQL 中一位最小的数据类型是什么?

The minimum data type of one bit can be bit(1). The syntax is as follows -

yourColumnName bit(1)

To understand the above syntax, let us create a table. The query to create the table is as follows -

mysql> create table bitDemo
   -> (
   -> isValid bit(1)
   -> );
Query OK, 0 rows affected (0.49 sec)

Now you can check all the details of the table with the help of SHOW CREATE command. The query is as follows -

mysql> show create table bitDemo;

This is the output -

+---------+-----------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                |
+---------+-----------------------------------------------------------------------------------------------------------------------------+
| bitDemo | CREATE TABLE `bitdemo` (`isValid` bit(1) DEFAULT NULL) ENGINE =InnoDB DEFAULT CHARSET =utf8mb4 COLLATE =utf8mb4_0900_ai_ci  |
+---------+-----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Use the insert command to insert some records in the table. The query is as follows -

mysql> insert into bitDemo values(0);
Query OK, 1 row affected (0.13 sec)
mysql> insert into bitDemo values(1);
Query OK, 1 row affected (0.10 sec)
mysql> insert into bitDemo values(1);
Query OK, 1 row affected (0.07 sec)
mysql> insert into bitDemo values(0);
Query OK, 1 row affected (0.14 sec)

Use the select statement to display all records in the table. The query is as follows -

mysql> select *from bitDemo;

This is the output -

+---------+
| isValid |
+---------+
|         |
|         |
|         |
|         |
+---------+
4 rows in set (0.00 sec)

To display the bit value, use the following query -

mysql> select isValid+0 from bitDemo;

The following is the output -

+-----------+
| isValid+0 |
+-----------+
| 0         |
| 1         |
| 1         |
| 0         |
+-----------+
4 rows in set (0.00 sec)

The above is the detailed content of What is the smallest one-digit data type in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete