1. employees table- emp_id is the primary key
2. department table-dept_id is the primary key.
3. Create or replace View emp_dept AS select e.emp_id, e.last_name, d.dept_id

From employees e, department d
4. update emp_dept
set last_name = 'munir'
where emp_id = 11

ORA-01779: cannot modify a column which maps to a non key-preserved table

Can someone pls tell me how i can fix it?

Thanks.

Recommended Answers

All 3 Replies

Why do you have the department table as part of the query? I would only guess that the last name resides in the employees table. You shoudl try something like this

UPDATE employees SET last_name = 'munir' WHERE emp_id = 11

You cannot update (or insert/delete -- DML operations) a view. You can update a table, which will reflect on the view.

Member Avatar for hfx642

Also...
Your view would show everyone working in every department.
I suspect that this is NOT the case.
Add a Where clause to your view.
Possibly...

Where E.Dept_ID = D.Dept_ID;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.