Oracle-创建检查约束 [英] Oracle - Create check constraint

查看:123
本文介绍了Oracle-创建检查约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个具有两列的表,这些列具有检查约束,即Col2值应基于Col1的值.我想在此提一下以下内容:

如果Col1值为"A"
那么Col2值应在10到20之间.

如果Col1值为``B''
那么Col2值应该在20到30之间

我知道,我们可以使用触发器来实现这一目标.我们可以通过在表级别声明检查约束来实现这一目标吗?

预先谢谢您.

I need to create a table with two columns having check constraint that Col2 value should be based on the values of Col1. I would like to mention this as below :

if Col1 value is ''A''
then Col2 value should be between 10 and 20

if Col1 value is ''B''
then Col2 value should be between 20 and 30

I know, we can achieve this using triggers. Can we achieve this by declaring a check constraint at table level.

Thank you in advance.

推荐答案

否.约束需要比这更简单,您正在描述需要在代码中检查的规则.
No. A constraint needs to be simpler than that, you''re describing rules that need to be checked in code.


这篇关于Oracle-创建检查约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆