oracle将字段nullable设为Y,Oracle 10g中约束与列属性NULLABLE的关系

结论: columname type not null与check (columnname is not null)的结果是不一样的 因此: 1、不需要手工去匹配NULLABLE属性,当

结论:

columname type not null与check (columnname is not null)的结果是不一样的

因此:

1、不需要手工去匹配NULLABLE属性,当所有显式导致NULLABLE由Y变N的约束被删除后,NULLABLE自然会恢复为Y。

2、尽量不要使用CHECK来实现NOT NULL,可以使用MODIFY或直接在字段后声明

drop table zwxtest04;

create table zwxtest04

(

id integer

);

alter table zwxtest04 add constraint zwxtest04c2 check (id is not null);

select * from user_tab_columns where table_name='ZWXTEST04';

select * from user_constraints where table_name='ZWXTEST04';

--NULLABLE 为Y ,约束并不会导致NULLABLE变动

drop table zwxtest04;

create table zwxtest04

(

id integer not null

);

select * from user_tab_columns where table_name='ZWXTEST04';

select * from user_constraints where table_name='ZWXTEST04';

-- NULLABLE 为N ,同时自动添加一个C型的NOT NULL的约束

drop table zwxtest04;

create table zwxtest04

(

id integer

);

alter table zwxtest04 id not nul;

select * from user_tab_columns where table_name='ZWXTEST04';

select * from user_constraints where table_name='ZWXTEST04';

-- NULLABLE 为N ,,同时自动添加一个C型的NOT NULL的约束

drop table zwxtest04;

create table zwxtest04

(

id integer

);

alter table zwxtest04 add constraint zwxtest04c3 primary key (id );

select * from user_tab_columns where table_name='ZWXTEST04';

select * from user_constraints where table_name='ZWXTEST04';

-- NULLABLE 为N ,创建P型约束,创建UNIQUE索引

alter table zwxtest04 drop constraint zwxtest04c3 ;

--NULLABLE为Y

本文永久更新链接地址:

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值