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
轉載于:https://www.cnblogs.com/QinQouShui/archive/2010/11/05/1869950.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的oralce10g中约束与列属性NULLABLE的关系的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 欢迎参加天津PDC Party的活动
- 下一篇: 有一种时刻叫大四