If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Insert into view that is using join fails

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-17-09, 08:27
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Insert into view that is using join fails

Hi,
using DB2 v9.5 I have the following sample:

db2 create table admin.tab1 (col1 int not null primary key, col2 char(20), col3 int)
db2 create table admin.tab2 (col3 int not null primary key, col4 char(20))
db2 alter table admin.tab1 add foreign key (col3) references admin.tab2 (col3) on delete restrict on update restrict
db2 create view admin.view as select a.col1, a.col2, b.col3, b.col4 from admin.tab1 a, admin.tab2 b where a.col3=b.col3
db2 insert into admin.view values (1,'AAA',100, 'BBB')

Insert statements fails with error message:
DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0150N The target fullselect, view, typed table, materialized query table, or staging table in the INSERT, DELETE, UPDATE, or MERGE statement is a target for which the requested operation is not permitted. SQLSTATE=42807

Why this insert does not work?
Regards
Reply With Quote
  #2 (permalink)  
Old 02-17-09, 08:31
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
It looks there is a limitation when inserting into view. I checked documentation:

==========
A view or a fullselect is read only if the SELECT statement of
the view or the fullselect contains any of the following:

A FROM clause that identifies one of the following:

- More than one table or view

==========

Last edited by grofaty; 02-18-09 at 02:18.
Reply With Quote
  #3 (permalink)  
Old 02-17-09, 09:35
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
You can use INSTEAD OF Triggers to 'write' to views.
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 02-18-09, 02:21
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
sathyaram_s, thanks, that is good point.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On