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 last published in July 2002

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

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.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close