当前位置: 移动技术网 > IT编程>数据库>Oracle > check约束

check约束

2018年11月24日  | 移动技术网IT编程  | 我要评论
 1 -- 删除表
 2 drop table check_test;
 3 -- 不为空,不为null的值只能是0,1(不为空,值只能是0,1)
 4 create table check_test(
 5  default_flag number(1) not null
 6  -- 检查约束
 7  check (default_flag in(0,1))
 8 );
 9 
10 -- 可以为null,不为null的值只能是0,1(null,0,1)
11 create table check_test(
12  default_flag number(1)
13  -- 检查约束
14  check (default_flag in(0,1))
15 );
16 
17 
18 -- 测试
19 insert into check_test(default_flag) values(0);
20 
21 insert into check_test(default_flag) values(1);
22 
23 insert into check_test(default_flag) values(2);
24 
25 insert into check_test(default_flag) values(3);
26 
27 insert into check_test(default_flag) values(null);
28 
29 select * from check_test;

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网