oracle之check约束小结

一下是Ocp考试指导中,对于oracle约束的描述:

The constraint types supported by the Oracle database are as follows:
UNIQUE
NOT NULL
PRIMARY KEY
FOREIGN KEY
CHECK
Constraints have names. It is good practice to specify the names with a standard naming convention, but if they are not explicitly named, Oracle will generate names.

由上可知,每一个约束都有名称,最好的做法是在定义约束是显式的命名,如果没有显式命名,那么系统会提供一个名字。

Check Constraints
A check constraint can be used to enforce simple rules, such as that the value entered in a column must be within a range of values. The rule must be an expression which will evaluate to TRUE or FALSE. The rules can refer to absolute values entered as literals or to other columns in the same row and may make use of some functions.
As many check constraints as you want can be applied to one column, but it is not possible to use a subquery to evaluate whether a value is permissible or to use functions such as SYSDATE.

check约束可用来执行简单的规则,例如在列中输入的值范围必须在一个数据范围之间。这个表达式结果必须为真或者假。某一行可以有多个check约束,但是不能使用子查询或者某些函数如sysdate。

CHECK Constraint

The chack constraints defines a condition that each row must satisfy . The condition can use the same constructs as the query conditions,with the following exceptions:

References to the CURRVAL,NEXTVAL,LEVEL,and ROWNUM pseudocolumns Calls to SYSDATE,UID,USER,and UESRENV functions

Queries that refer to other values in other rows

A single column can have multiple CHECK constraints that refer to the column in its definition. There is no limit to the number of CHECK constraints that you can define on a column.CHECK constraints can be defined at the column level or table level.

check约束必须作用在表中定义的字段上,视图中不可使用check约束,以下情况不可使用在check约束中:

CURRVAL,NEXTVAL,LEVEL,ROWNUM伪列,SYSDATE,UID,USER, UESRENV函数不能使用在check约束中,

涉及其他行值得查询。

单个列可以定义多个参考列的check约束,单个列所能定义的check约束数据没有限制。check约束可以定义列级的,也可以定义表级的。

 

你可能感兴趣的:(oracle之check约束小结)