在这里,总结一下,对约束的操作,Constraints,有5种类型:
-
Check
-
Not NULL
-
Primary key
-
Unique
-
Foreign Key
1. Check
确保指定列中的值符合一定条件。check约束可以涉及该行的同属于check约束的其他数据列,但是不能涉及其他行或者其他表。
单一的数据列可以有多个check保护,一个check约束可以保护多个数据列。
可以在create table时创建check约束,也可以在alter table时修改表的约束。
其语句格式为 constraint [约束名] check(codition). 约束名不是必须的,但是最好有一个名字。
create table t_ygy_demo_editor
(
editor_key varchar2(9) not null,
editor_last_name varchar2(40),
editor_first_name varchar2(30) not null,
editor_hire_date date,
editor_active char(1)
constraint active_ck check (editor_active in ('Y','N'))
);
alter table 表名 add constraint chka1 check(a1 in (1,0));
alter table 表名 disab