Home » RDBMS Server » Performance Tuning » Update columns of one table using another table (Oracle 10G)
Update columns of one table using another table [message #493200] Sun, 06 February 2011 12:18 Go to next message
priyankt
Messages: 10
Registered: February 2011
Junior Member
Hello Experts,

I am trying to update columns of TableA with the columns of TableB.
Both these tables have 60,000 rows each. I tried this operation using following 2 queries:

Query 1

Update TableA A
set 
(A.col1,A.col2,A.col3)=(select B.col1,B.col2,B.col3
                        from TableB
                         where A.CODE=B.CODE)



Query 2
Update TableA A
set
(A.col1,A.col2,A.col3)=(select B.col1,B.col2,B.col3
                        from TableB
                         where A.CODE=B.CODE)
where exists
A.code = (select B.code
           from TableB B
           where A.code=B.code) 


When i execute these two above queries, it keeps executing indefinitly Sad

Please suggest simple and quick method for performing this operation.

Regards
Priyanka
Re: Update columns of one table using another table [message #493202 is a reply to message #493200] Sun, 06 February 2011 12:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Read http://www.orafaq.com/forum/mv/msg/84315/433888/102589/#msg_433888 and post the required information.

Regards
Michel

Re: Update columns of one table using another table [message #493203 is a reply to message #493200] Sun, 06 February 2011 12:28 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
Do you have any indexes on the tables? An index on the code column in each table might help.
Re: Update columns of one table using another table [message #493204 is a reply to message #493202] Sun, 06 February 2011 12:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
post results from SQL below
SELECT COUNT(*)
FROM   tablea a
WHERE  a.code IN (SELECT b.code
                  FROM   tableb b
                  WHERE  a.code = b.code)  
Re: Update columns of one table using another table [message #493253 is a reply to message #493204] Mon, 07 February 2011 02:08 Go to previous message
priyankt
Messages: 10
Registered: February 2011
Junior Member
Hello All,
Thanks a lot for reverting back.


I have now created indexes on both the tables (on code field), still there is not much change in the execution time.
SELECT COUNT(*)


i did a explain plan for
FROM tablea a
WHERE a.code IN (SELECT b.code
FROM tableb b
WHERE a.code = b.code)


SELECT COUNT(*)
FROM   tablea a
WHERE  a.code IN (SELECT b.code
                  FROM   tableb b
                  WHERE  a.code = b.code)  

Gives 60,000 rows


I did a explain plan for query below
Update TableA A
set 
(A.col1,A.col2,A.col3)=(select B.col1,B.col2,B.col3
                        from TableB
                         where A.CODE=B.CODE)


Below are the results:

60969 UPDATE STATEMENT
UPDATE tablea
60969 TABLE ACCESS FULL tablea
685 TABLE ACCESS BY INDEX ROWID Tableb
274 INDEX RANGE SCAN Tableb_IDX1

Previous Topic: tunning
Next Topic: Real time speed improvements & autotrace results.
Goto Forum:
  


Current Time: Wed Apr 24 08:31:50 CDT 2024