非空约束 NOT NULL

create table studentkd
(

id int primary key,
name varchar(20) not null, --姓名非空 必须填
age int

);

insert into studentkd(id,name,age)
values(1,'张三',18)

--违规插入 触发not null
-- 错误:姓名没给值,违反非空约束
INSERT INTO studentkd(id, age)
VALUES (2, 19);

--改成非空 取消非空约束
alter table studentkd
alter column name varchar(20) null;

posted @ 2026-05-02 11:43  菜鸟的奋斗军  阅读(8)  评论(0)    收藏  举报