【发布时间】:2020-01-05 13:57:31
【问题描述】:
我有三张桌子。
Stude_course 及其记录如下
empid ename emp_status emp_year
1 Raja 6 1
2 Poo 5 2
3 Bhasker 6 3
Student1 表包含以下记录
empid ename emp_status
1 Raja 6
2 Poo 6
3 Bhasker 6
Stud_year 包含以下记录
empid emp_year
1 1
2 1
3 1
我需要一个查询来使用 student1.emp_status 更新 stude_course.emp_status 并使用 stud_year.emp_year 更新 stude_course.emp_year。为了更新这些记录,我使用了下面的查询
update
(
select sc.emp_status stud_emp_status,sc.emp_year stud_emp_year,s.emp_status stud_status,sy.emp_year stud_year from stude_course sc,student1 s,stud_year sy
where sc.empid = s.empid
and s.empid = sy.empid
and sc.empid = 2) st
set st.stud_emp_status = st.stud_status, st.stud_emp_year = st.stud_year;
我已经使用 equi join 连接了三个表,并为整个连接的表指定了一个别名 st,还为列名指定了别名,然后我尝试使用给定的别名表和列名来更新值
预期结果:
empid ename emp_status emp_year
1 Raja 6 1
2 Poo 6 1
3 Bhasker 6 1
But i got error like
SQL Error: ORA-01779: cannot modify a column which maps to a non key-preserved table
01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
*Cause: An attempt was made to insert or update columns of a join view which
map to a non-key-preserved table.
*Action: Modify the underlying base tables directly.
【问题讨论】:
标签: sql oracle join sql-update