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

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

PHPz
Release: 2023-09-02 12:05:02
forward
760 people have browsed it

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

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

yourColumnName bit(1)
Copy after login

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)
Copy after login

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;
Copy after login

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)
Copy after login

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)
Copy after login

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

mysql> select *from bitDemo;
Copy after login

This is the output -

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

To display the bit value, use the following query -

mysql> select isValid+0 from bitDemo;
Copy after login

The following is the output -

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template