Oracle 10g中約束與列屬性NULLABLE的關係

來源:互聯網
上載者:User

Oracle 10g中約束與列屬性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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.