oracle 表约束非空,表的约束--非空和检查约束 not null, check

1 列级实现

drop table testcons_lzh_88;

create table testcons_lzh_88(

id number primary

key,

name varchar2(20) not

null,

userid varchar2(18)

unique,

sal number(11,2)

check(sal>2000)

);

insert into testcons_lzh_88(id, userid, sal)

values(1, '1234', 3000)

*

ERROR at line 1:

ORA-01400: cannot insert NULL into

("OPENLAB"."TESTCONS_LZH_88"."NAME")

insert into testcons_lzh_88 values(1, 'li',

'1234', 3000);

insert into testcons_lzh_88(id, name, userid,

sal) values(4, 'zhang', '1234', 1500);

*

ERROR at line 1:

ORA-02290: check constraint

(OPENLAB.SYS_C0027472) violated

2 表级实现

drop table testcons_lzh_88;

create table testcons_lzh_88(

id number unique,

name varchar2(20) not

null,

userid varchar2(18)

unique,

sal number(11,2)

check(sal>2000)

);

insert into testcons_lzh_88 values(1, 'li',

'1234', 3000);

insert into testcons_lzh_88 values(1,

'zhang','123', 3000);

insert into testcons_lzh_88 values(2,

'zhang','123', 3000);

drop table testcons_lzh_88;

create table testcons_lzh_88(

id number ,

name varchar2(20) not

null,

userid

varchar2(18),

sal number(11,2),

unique(id,

userid),

chekc(sal>3000)

);

3

从业务层面,没有多个字段联合非空的需要,所有Oracle没有提供非空约束的表级实现。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值