简体   繁体   English

Oracle SQL更新视图

[英]Oracle SQL update a view

I have been working with this table view for a while. 我已经使用此表视图已有一段时间了。 Research has not proven helpful. 研究尚未证明是有帮助的。 Here is what i have. 这就是我所拥有的。 I have 3 tables - Loan_01, employee_01 and tool_01 我有3个表格-Loan_01,employee_01和tool_01

Of those 3 tables i am pulling 7 columns to view 在这3张桌子中,我要拉7列才能查看

SELECT
l.tool_desc,
t.tool_id_from_mfg,
t.tool_mfg,
e.employee_name,
l.job_desc,
l.loan_active,
l.loan_status_change_date
FROM loan_01 l
join employee_01 e ON l.employee_email=e.employee_email
join tool_01 t ON l.tool_no=t.tool_no ;

It successfully creates and runs returning data. 它成功创建并运行返回数据。 I attempt to update with 我尝试更新

    UPDATe TOOL_LOAN_MINE
SET loan_active = 'Inactive',
loan_status_change_date = SYSDATE
WHERE loan_status_change_date = '18-SEP-16' AND tool_out_date = '16-SEP-16'
AND loan_active = 'Active';

It returns the ORA-01779 cannot modify a column which maps to a non key-preserved table. 它返回ORA-01779无法修改映射到非键保留表的列。

If i read this post correctly - https://dba.stackexchange.com/questions/127708/updating-a-view-on-multiple-joined-tables 如果我正确阅读了这篇文章-https: //dba.stackexchange.com/questions/127708/updating-a-view-on-multiple-joined-tables

As long as i am making a change to the multiple (Loan) table it should update. 只要我对倍数(贷款)表进行更改,它就应该更新。 What am i doing wrong? 我究竟做错了什么?

Thanks in advance 提前致谢

The parent tables (employee and tool) would need explicit (non-deferrable) unique constraints on the referenced columns (employee_email and tool_no respectively). 父表(员工和工具)在引用的列(分别为employee_email和tool_no)上需要显式(不可延迟)唯一约束。

While tool_no looks like it could be the primary key, I suspect you either don't have a unique constraint on email, or it is on some function such as UPPER(email) 虽然tool_no看起来可能是主键,但我怀疑您对电子邮件没有唯一的约束,或者对某些功能(例如UPPER(email))没有限制

If you had two employees with the same email (which might be legitimate if the employee table includes ex-employees with email addresses reused), then even though only one loan record would be updated, that would affect multiple rows in the view. 如果您有两名雇员使用同一封电子邮件(如果employee表中包括重复使用电子邮件地址的前雇员,这可能是合法的),那么即使仅更新一份贷款记录,也会影响视图中的多行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM