Home > Database > Mysql Tutorial > body text

Inserting NULL value into INT column in MySQL?

王林
Release: 2023-09-01 11:05:03
forward
930 people have browsed it

在 MySQL 中将 NULL 值插入 INT 列?

You can insert NULL value into an int column using condition, i.e. the column must not have NOT NULL constraint. The syntax is as follows.

INSERT INTO yourTableName(yourColumnName) values(NULL);
Copy after login

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

mysql> create table InsertNullDemo
-> (
-> StudentId int,
-> StudentName varchar(100),
-> StudentAge int
-> );
Query OK, 0 rows affected (0.53 sec)
Copy after login

The following is the query that inserts NULL whenever you don't pass any value for the column. This column here is StudentAge. MySQL inserts null values ​​by default. The query to insert records is as follows.

mysql> insert into InsertNullDemo(StudentId,StudentName) values(101,'Mike');
Query OK, 1 row affected (0.19 sec)

mysql> insert into InsertNullDemo values(101,'Mike',NULL);
Query OK, 1 row affected (0.24 sec)
Copy after login

Display all records in the table and check whether a NULL value is inserted in the INT column. The query is as follows.

mysql> select *from InsertNullDemo;
Copy after login

The following is the output showing NULL in the INT column.

+-----------+-------------+------------+
| StudentId | StudentName | StudentAge |
+-----------+-------------+------------+
| 101       | Mike       | NULL       |
| 101       | Mike       | NULL       |
+-----------+-------------+------------+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of Inserting NULL value into INT column 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