分配给不能为空的MySQL列的内容是什么?
如果列不能为空,则使用NOTNULL进行定义。让我们首先创建一个表,其中一列为NOTNULL-
mysql> create table DemoTable1895 ( Id int NOT NULL, FirstName varchar(20), LastName varchar(20) NOT NULL );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1895 values(100,'John','Smith'); mysql> insert into DemoTable1895 values(NULL,'Chris','Brown'); ERROR 1048 (23000): Column 'Id' cannot be null mysql> insert into DemoTable1895 values(102,'Carol',NULL); ERROR 1048 (23000): Column 'LastName' cannot be null mysql> insert into DemoTable1895 values(103,NULL,'Miller');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1895;
这将产生以下输出-
+-----+-----------+----------+ | Id | FirstName | LastName | +-----+-----------+----------+ | 100 | John | Smith | | 103 | NULL | Miller | +-----+-----------+----------+ 2 rows in set (0.00 sec)