在 MySQL 中将 NULL 值插入 INT 列?
您可以使用条件将 NULL 值插入到 int 列中,即该列不得具有 NOT NULL 约束。语法如下。
INSERT INTO yourTableName(yourColumnName) values(NULL);登录后复制
mysql> create table InsertNullDemo -> ( -> StudentId int, -> StudentName varchar(100), -> StudentAge int -> ); Query OK, 0 rows affected (0.53 sec)登录后复制
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)登录后复制
mysql> select *from InsertNullDemo;登录后复制
+-----------+-------------+------------+ | StudentId | StudentName | StudentAge | +-----------+-------------+------------+ | 101 | Mike | NULL | | 101 | Mike | NULL | +-----------+-------------+------------+ 2 rows in set (0.00 sec)登录后复制