这个约束加不了???

小灰狼 2020-12-09 04:28:17
表中有两个字段,想要加个约束,条件是:
1、字段 a 可以为空,当 a 为空时,没有要求
2、当字段 a 非空时,要求字段 b 也必须非空

加约束的语句:
alter table shpfront add constraint 
check (
shop_id is null
or (
shop_id is not null and duty_id is not null
)
);


报错
ORA-02438: 列检查约束条件无法引用其他列
...全文
227 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
卖水果的net 2020-12-09
  • 打赏
  • 举报
回复
使用插入行触发器来解决这种复杂需求 。
nayi_224 2020-12-09
  • 打赏
  • 举报
回复

alter table shpfront add constraint aaa
check (
	shop_id is null 
	or (
		shop_id is not null and duty_id is not null
	)
);

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧