3-5 oracle 的表操作——非空约束
本节目标
- 了解什么是非空约束
- 掌握创建表和修改表时添加非空约束的方法
- 掌握删除非空约束与删除其他约束的区别
非空(not null)约束
- not null约束用于确保列不能为NULL,如果在列上定义了NOT NULL约束,那么插入数据时,必须为该列提供数据;当更新列数据时,不能将其值设置为NULL。
- 非空(not null)约束是列级约束。
列级约束与表级约束定义上的区别
-
列级约束
-
column [CONSTRAINT constraint_name] constraint_type,
-
说明:列级约束必须跟在列的定义后面
-
表级约束
-
colum,…
[CONSTRAINT constraint_name] constraint_type
(column,…), -
说明:表级约束不与列一起,而是单独定义的。
创建表时添加非空(not null)约束
create table student(
sid number(8,0),
name varchar2(20) not null,
sex char(2) constraint nn_sex not null,
birthday date,