ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Constraint State(disable/enable validate/noalidate)

Constraint State(disable/enable validate/noalidate)

原创 Linux操作系统 作者:lixianlinde 时间:2013-01-07 09:59:19 0 删除 编辑
At any time, every constraint is either enabled or disabled, and validated or not 
validated. Any combination of these is syntactically possible:
 ENABLE VALIDATE   It is not possible to enter rows that would violate the 
constraint, and all rows in the table conform. to the constraint.
 DISABLE NOVALIDATE  Any data (conforming or not) can be entered, and 
there may already be nonconforming data in the table.
 ENABLE NOVALIDATE  There may already be nonconforming data in the 
table, but all data entered now must conform.
 DISABLE VALIDATE   An impossible situation: all data in the table conforms 
to the constraint, but new rows need not. The end result is that the table is 
locked against DML commands.



http://blog.csdn.net/priestmoon/article/details/6197379
enable/disable validate/novalidate
以上两项都是对约束的设置选项

enable/disable   
针对新插入/更新的数据进行/不进行约束验证,默认enable。
enable时,如果是主键或唯一键,首先查看列上是否有索引,如果有就用。没有就新建。
disable时,如果是主键或唯一键,会删除enable时新建的索引,但自定义索引不受影响。

validate/novalidate 
针对已有数据进行/不进行约束验证,默认validate

①enable validate
对新数据做验证,同时保证旧数据验证通过。如果旧数据违反约束,则必须修改或删除这部分数据,否则不能创建约束。

②enable novalidate
对新数据做验证,同时忽略旧数据的约束合法性。如果旧数据违反主键/唯一键约束,并且事先没有定义该列的非唯一索引(nonunique index),则本设置不能通过。因为在enable时,系统会新建一个unique index,而旧数据显然不能支持这一操作。所以要使本设置生效,必须对违反主键/唯一键约束的列上添加nonunique index。方法是create index on ()。

③disable validate
保证已有数据的约束合法性,同时禁止表的insert/update/delete操作。

④disable novalidate
忽略约束合法性

ORACLE中,约束分deferred 跟 immediate 2种:
  deferred:如果 Oracle 在事务提交(commit)时才对约束执行检查,则称此约束是延迟的(deferred)。如果数据违反了延迟约束,提交操作将导致事务被回滚(undo)。 
  immediate:如果约束是即时的(immediate)(非延迟的),则此约束将在语句执行结束后进行检查。如果数据违反了延迟约束,语句将被立即回滚。

一般情况下,我们用的约束初始都是immediate型的(默认),而且不好转为deferred型。但是如果初始是deferrable(需要手动指定),那deferred跟immediate 2种状态可以随意转换。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24570973/viewspace-752225/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-12-25

  • 博文量
    24
  • 访问量
    26751