偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Oracle數(shù)據(jù)庫約束

數(shù)據(jù)庫 Oracle
Oracle數(shù)據(jù)庫是甲骨文公司的一款關系數(shù)據(jù)庫管理系統(tǒng)。到目前仍在數(shù)據(jù)庫市場上占有主要份額。下文中主要為大家講解Oracle數(shù)據(jù)庫的約束。

Oracle數(shù)據(jù)庫是大家平時的工作中經(jīng)常會用到的,本文將為大家?guī)鞳racle數(shù)據(jù)庫約束的講解,希望對大家能夠有所幫助。

最近一張表上有兩列字段,要求這兩列要么都有值,要么都為空,簡單的table定義沒辦法實現(xiàn)這種要求,需要利用Oracle的constraint(約束)機制。約束主要是用來保證數(shù)據(jù)的完整性。

可以從TOAD的設置上,很容易看到約束分為4種,分別是主鍵(Primary Key),檢查(Check),唯一性(Unique),外鍵(Foreign Key)。另外還有兩種是NOT NULL和REF,REF就是其中的一列或者幾列是另外一張表中的值。

下面是對著6中的詳細介紹。

NOT NULL constraint prohibits a database value from being null.

Unique constraint prohibits multiple rows from having the same value in the same column or combination of columns but allows some values to be null.

Primary Key constraint combines a NOT NULL constraint and a unique constraint in a single declaration. It prohibits multiple rows from having the same value in the same column or combination of columns and prohibits values from being null.

Foreign Key constraint requires values in one table to match values in another table.

Check constraint requires a value in the database to comply with a specified condition.

REF column by definition references an object in another object type or in a relational table. A REF constraint lets you further describe the relationship between the REF column and the object it references.

toad create constraint step 1

對于我們的要求,符合的是Check,可以通過增加一個條件是( A is null and B is null ) or ( A is not null and B is not null) 的約束來實現(xiàn)。

對于約束,主要的狀態(tài)有兩種,一個是Status on Creation,也就是在表中增加數(shù)據(jù)或修改數(shù)據(jù)時是否使用約束,可選值是Enabled和Disabled;另外一種是Validation,它表示是否對表中現(xiàn)有的數(shù)據(jù)是否進行驗證,可選值是Validate和NoValidate。

toad create constraint step 2

對于上面這兩種狀態(tài),有4種組合,下面是對著四種的詳細介紹。

ENABLE VALIDATE is the same as ENABLE. The constraint is checked and is guaranteed to hold for all rows.

ENABLE NOVALIDATE means that the constraint is checked, but it does not have to be true for all rows. This allows existing rows to violate the constraint, while ensuring that all new or modified rows are valid.

In an ALTER TABLE statement, ENABLE NOVALIDATE resumes constraint checking on disabled constraints without first validating all data in the table.

DISABLE NOVALIDATE is the same as DISABLE. The constraint is not checked and is not necessarily true.

DISABLE VALIDATE disables the constraint, drops the index on the constraint, and disallows any modification of the constrained columns.

約束的設置還有一個延遲性設置,默認是非延遲的,也就是Initially Immediate,這種情況下任何的修改都會進行校驗,另外一種是延遲的,也就是Intially Deferred,會在所有修改完成后commit的時候校驗,進而引發(fā)回滾。

 

責任編輯:迎迎 來源: 中國IT實驗室
相關推薦

2011-08-10 15:38:12

ConstraintOracle

2011-07-20 12:34:49

SQLite數(shù)據(jù)庫約束

2009-03-23 10:11:59

Oracle數(shù)據(jù)庫唯一約束

2011-08-10 16:01:11

OracleConstraint

2015-08-21 12:59:38

Oracle數(shù)據(jù)庫

2011-03-10 13:24:26

2010-04-23 09:23:44

Oracle 數(shù)據(jù)庫

2011-03-16 08:54:45

Oracle數(shù)據(jù)庫索引

2011-05-19 13:25:14

Oracle數(shù)據(jù)庫

2011-04-11 09:39:46

Oracle約束

2011-03-29 10:47:49

ORACLE數(shù)據(jù)庫

2010-06-17 12:59:07

Oracle

2011-05-24 14:27:42

2010-04-19 16:01:54

2010-04-02 13:59:08

Oracle數(shù)據(jù)庫

2010-04-14 15:14:11

Oracle數(shù)據(jù)庫

2011-03-07 13:30:53

Oracle數(shù)據(jù)庫

2011-08-18 11:18:25

Oracle唯一約束唯一索引

2011-10-09 09:38:03

OracleNoSQL

2010-10-28 15:56:21

ORACLE數(shù)據(jù)庫設置
點贊
收藏

51CTO技術棧公眾號