• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Inserting Into a view that results from join of two tables

 
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a table tab1
create table tab1(stu_name varchar2(30),dept_id number);


I created another table tab2
create table tab2(dept_name varchar2(30),department_id number);


Then I created a view

Create view STView(sname,dname) as
select stu_name,dept_name
from tab1 join tab2
on dept_id=department_id;

Now When I try to insert into the view
insert into STview values('Alex','CS');
It syas

" cannot modify a column which maps to a non key-preserved table".
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be better if you posted a DDL statements you used to create the tables. Firstly, others would be able to test your example (see SSCCE), and secondly, in this case the existence (or the lack of) of primary keys and foreign constraints is crucial, and we don't see it from the descriptions.

Nevertheless, the error message mentions non key-preserved table. Thomas Kyte has probably the simplest definition what key-preserved view means:

Thomas Kyte wrote:Key preserved means the row from the base table will appear AT MOST ONCE in the output view on that table


See the entire discussion.

I haven't ever tried to insert into a join, but I'd say that it would only be possible if the tables in the join were in a 1:1 relationship (and declared by existing constraints as such), which is quite rare.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic