Q

Replacing values in table a with values from table b

What is the command sequence for replacing values in table a with values in table b?

If the two tables are identical, and you want to completely replace contents of table a with table b, you could write a simple procedure to do the following steps:

  1. DELETE or TRUNCATE table A
  2. INSERT INTO table A SELECT * FROM table B
  3. COMMIT
You could also simply drop table A and use the CREATE TABLE AS....statement to re-create table A using table B:
CREATE TABLE A as SELECT * FROM table B
;
If you don't want to simply replace the entire contents, but want to match like rows and update, then you can write a statement or procedure to:
  1. Match all the rows of table B to their associated row (by key value) in table A
  2. When a match is found, replace the column values in table A with the values in table B
I hope this gives you some ideas!

For More Information


This was first published in July 2002

Dig deeper on Oracle and SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close