问题描述
我只想创建用于检查员工工资不能超过经理工资的触发器。
有一张表:
EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SALARY,DEPTNO)
FK: 经理参考EMPNO
谢谢。
有一张表:
EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SALARY,DEPTNO)
FK: 经理参考EMPNO
谢谢。
专家解答
我会用不同的方式来做,因为用触发器比你想象的要困难得多
SQL> create table emp as select * from scott.emp; Table created. SQL> alter table emp add primary key ( empno ); Table altered. -- -- get our data initially valid -- SQL> SQL> update emp set sal = 2900 2 where empno in ( 7902,7788); 2 rows updated. -- -- I'm going to create a materialized view that holds all of the *violations* -- so it will be empty most of the time -- SQL> SQL> create materialized view log on emp with rowid including new values; Materialized view log created. SQL> SQL> create materialized view emp_mv 2 refresh fast on commit 3 as select e1.rowid rid1, e2.rowid rid2 4 from emp e1, 5 emp e2 6 where e1.mgr = e2.empno 7 and e1.sal > e2.sal; Materialized view created. -- -- now I add a constraint which says if I ever get a row in here, then my table data -- must not be valid -- SQL> alter table emp_mv add constraint emp_mv check ( 1=0); Table altered. SQL> update emp set sal = 3100 2 where empno = 7902; 1 row updated. SQL> commit; commit * ERROR at line 1: ORA-12008: error in materialized view or zonemap refresh path ORA-02290: check constraint (MCDONAC.EMP_MV) violated复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1444次阅读
2025-03-13 11:40:53
Oracle RAC ASM 磁盘组满了,无法扩容怎么在线处理?
Lucifer三思而后行
878次阅读
2025-03-17 11:33:53
RAC 19C 删除+新增节点
gh
538次阅读
2025-03-14 15:44:18
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
493次阅读
2025-03-13 14:38:19
Oracle 如何修改 db_unique_name?强迫症福音!
Lucifer三思而后行
424次阅读
2025-03-12 21:27:56
Oracle DataGuard高可用性解决方案详解
孙莹
365次阅读
2025-03-26 23:27:33
墨天轮个人数说知识点合集
JiekeXu
311次阅读
2025-04-01 15:56:03
XTTS跨版本迁移升级方案(11g to 19c RAC for Linux)
zwtian
278次阅读
2025-04-08 09:12:48
风口浪尖!诚通证券扩容采购Oracle 793万...
Roger的数据库专栏
266次阅读
2025-03-24 09:42:53
切换Oracle归档路径后,不能正常删除原归档路径上的归档文件
dbaking
264次阅读
2025-03-19 14:41:51