Ask the Expert

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?

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

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: