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 > update a table in one schema from a table in another schema

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-04, 14:12
globetrotcom globetrotcom is offline
Registered User
 
Join Date: Jan 2004
Posts: 23
update a table in one schema from a table in another schema

Using DB V7.2, and in the same database:

I have a table A in Schema A and a table B in Schema B.

How can I update table B with entries that table A has and table B does not.

Thanks
Reply With Quote
  #2 (permalink)  
Old 01-07-04, 14:25
Maor71 Maor71 is offline
Registered User
 
Join Date: Apr 2002
Posts: 188
Re: update a table in one schema from a table in another schema

Quote:
Originally posted by globetrotcom
Using DB V7.2, and in the same database:

I have a table A in Schema A and a table B in Schema B.

How can I update table B with entries that table A has and table B does not.

Thanks
Make sure that your loging user has access to both schemas but you can try the follwing, perhaps I am wrong..

update schemab.table
set schemaB.table.column = schemaA.table.column
where
schemaB.table.column = schemaA.table.column

I think this should work
Reply With Quote
  #3 (permalink)  
Old 01-07-04, 14:41
anil4321 anil4321 is offline
Registered User
 
Join Date: Feb 2003
Posts: 20
Re: update a table in one schema from a table in another schema

As long as you have your tables in the same database (Forget about Federated DB for a while), you can perform any join between your tables. Just use the fully qualified table name. If table name is TABLENAME and schema name is SCHEMA_NAME, then the fully qualified name is SCHEMA_NAME.TABLENAME.

I am sorry, I can not get the second part of your query.

What do you want to update - a column for all rows or create records in schemaB.tableB which are not present in schemaA.tableA.
Reply With Quote
  #4 (permalink)  
Old 01-07-04, 15:01
globetrotcom globetrotcom is offline
Registered User
 
Join Date: Jan 2004
Posts: 23
I want to insert new rows in table B that are not in table A, based on the values in certain combination of columns in table A and table B.
Reply With Quote
  #5 (permalink)  
Old 01-07-04, 15:49
anil4321 anil4321 is offline
Registered User
 
Join Date: Feb 2003
Posts: 20
Here it is:

insert into schemaB.tableB
(column1,column2)
select (column1, column2)
from schemaA.tableA
where column1 not in (select column1 from schemaB.tableB);

OR

insert into test2 (col1,col2) select a.col1, a.col2 from test1 a, test2 b where a.col2!=b.col2;
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