views:

165

answers:

3

hi,

i am using two tables in my oracle 10g. the first table having the keyword,count,id(primary key) and my second table having id, timestamp..

but i am doing any chages in the first table(keyword,count) it will reflect on the my second table timestamp.. i am using id as reference for both the tables...

table1:

CREATE TABLE Searchable_Keywords
(KEYWORD_ID NUMBER(18) PRIMARY KEY,
KEYWORD VARCHAR2(255) NOT NULL,
COUNT  NUMBER(18) NOT NULL,
CONSTRAINT Searchable_Keywords_unique UNIQUE(KEYWORD)
);

table2:

CREATE TABLE Keywords_Tracking_Report
(KEYWORD_ID NUMBER(18),
PROCESS_TIMESTAMP TIMESTAMP(8) 
);

how can update one table with reference of another table..

help me plz...

+1  A: 

Use an after insert or update trigger on table1 to manage table2.

BillThor
+1: Though I loathe triggers, and prefer to encapsulate this in a stored procedure instead...
OMG Ponies
A: 

Check this Question I think it can help you out:

http://stackoverflow.com/questions/2695116/update-multiple-table-column-values-using-single-query

JeremySpouken
A: 

You can use instead of trigger to do this.

For this you follow the below process

SQL> create or replace view v_for_update
2 as
3 select e.keyword,d.id,e.count
4 from Keywords_Tracking_Report  e, Keywords_Tracking_Report  d
5 where e.id=d.id
6 /

View created.

SQL> create or replace trigger tr_on_v_for_update
2 instead of update on v_for_update
3 begin
4
5 update Keyword_table set Keyword= :new.Keyword, count= :new.count
6 where id=:old.id;
7
8 update Keywords_Tracking_Report set timestamp= :new.timestamp
9 where id=:old.id;
12
13 end;
14 /

Trigger created.

Now with single sql statement you can update multiple tables

 SQL> update v_for_update set keyword='xyz',count = 2, timestamp = sysdate
 where id=1;
Bharat
the view is unnecessary, just create the trigger on the parent table...
OMG Ponies
This view is necessary because i was updating multiple tables with this view only. This was one approach for updating multiple tables
Bharat