您好,欢迎访问一九零五行业门户网

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
本文永久更新链接地址:
其它类似信息

推荐信息