oralce10g中约束与列属性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

posted @   秦秋随  阅读(618)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示