是的,我们可以按照以下语法传递NULL:
insert into yourTableName values(NULL,yourValue1,yourValue2,...N);
让我们首先创建一个表-
mysql> create table DemoTable1503 -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int -> );
使用insert命令在表中插入一些记录。由于我们在上面设置了NOT NULL,因此不会影响auto_increment-
mysql> insert into DemoTable1503 values(NULL,'Chris',25); mysql> insert into DemoTable1503 values(NULL,'David',28); mysql> insert into DemoTable1503 values(NULL,'Bob',45); mysql> insert into DemoTable1503 values(NULL,'Mike',57);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1503;
这将产生以下输出。自动增量以相同的方式打印(不为null)-
+----------+------------+-----------+ | ClientId | ClientName | ClientAge | +----------+------------+-----------+ | 1 | Chris | 25 | | 2 | David | 28 | | 3 | Bob | 45 | | 4 | Mike | 57 | +----------+------------+-----------+ 4 rows in set (0.00 sec)