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 > Inserting data into view

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-03, 07:33
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Inserting data into view

Hi,

My system: db2 v7.1 fp 5 on Windows 2000


1. I have table "x". There is no Primary key on this table!

Code:
CustomerID  CustomerName
1           'Customer A'
2           'Customer B'
2. I created view:
create view y as select * from x where CustomerID <> 1

3. I can make "select":
select * from y
Returns:
Code:
CustomerID  CustomerName
2           'Customer B'
4. Why does this sql works:
insert into y (1,'Customer Z')

I am inserting the data to the view, and data are inserted to the table. Why doesn't DB2 prevents to insert into view - on view is restriction "CustomerID <> 1"?

Thanks,
Grofaty
Reply With Quote
  #2 (permalink)  
Old 10-08-03, 08:37
neelamchalam neelamchalam is offline
Registered User
 
Join Date: Jul 2003
Location: india
Posts: 15
Re: Inserting data into view

Quote:
Originally posted by grofaty
Hi,

My system: db2 v7.1 fp 5 on Windows 2000


1. I have table "x". There is no Primary key on this table!

Code:
CustomerID  CustomerName
1           'Customer A'
2           'Customer B'
2. I created view:
create view y as select * from x where CustomerID <> 1

3. I can make "select":
select * from y
Returns:
Code:
CustomerID  CustomerName
2           'Customer B'
4. Why does this sql works:
insert into y (1,'Customer Z')

I am inserting the data to the view, and data are inserted to the table. Why doesn't DB2 prevents to insert into view - on view is restriction "CustomerID <> 1"?

Thanks,
Grofaty
Dear Grofaty,

1.what DB2 is doing correct, we have restriction with view not with the base table

2. after inserting (1,'Customer Z') , if you select you will get the same result which you got previously

3. if you want to restrict VIEW itself we can use the
WITH CHECK OPTION.

CREATE VIEW y AS SELECT * from x where CustomerID <> 1 WITH CHECK OPTION;

this view won't allow to update view or base table with (1,'Customer Z') such a data which is violating the CHECK OPTION.

4. if there is any thing else so please inform me so i can get more knowledge.

Thanking you,
Chalam N
Reply With Quote
  #3 (permalink)  
Old 10-08-03, 13:17
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
You can also define a column contraint on the table.
Reply With Quote
  #4 (permalink)  
Old 10-10-03, 01:19
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

Thanks neelamchalam, that is solution I have been looking for.
Thank you Markus_A. That is also a good point.

Thanks,
Grofaty
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