すぐに学ぶ:https://edu.csdn.net/course/play/4364/77143?utm_source=blogtoedu
# 创建表时指定非空列
create table fk
(
sid int not null,
sname varchar(20) not null,
cardid varchar(20)
)
指定されたnull以外の列の後** SQL Serverの、NULLを追加したレコードの成功を追加することはできません。
MySQLは、非空の列を指定しているが、追加のエラー・レコードは、列が、文字「」(空ではないが、無コンテンツNULL)に挿入される挿入された0の数値であるような、ヌル値ではありません。
insert into fk (sid, sname) values (1, null) --报错,不允许插入空值
# 如何查询没有内容的记录?
select * from fk where sname=''
# 如何查询为空的记录?
select * from fk where cardid is null
# 增加非空约束
alter table fk modify column sid integer(11) NOT NULL
# 取消非空约束,增加默认值
alter table fk modify column sid integer(11) default NULL