dbTalk Databases Forums  

Best and efficient way of overwriting a existing record in a table

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Best and efficient way of overwriting a existing record in a table in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Karen Middleton
 
Posts: n/a

Default Best and efficient way of overwriting a existing record in a table - 11-10-2004 , 04:34 AM






I am loading data from one table to another the structure of both the
tables are the same.

When I copy from the staging table to the main table I want the
staging table records to overwrite the records with the same key in
the main table.

So for example the following are the keys in both tables:

Key columns
===========
Month
Material
Year
Customer
Store

Non-Key Columns
===============
SalesQty
Sales$

If the staging table as a record with the same key columns values as
the main table I want to overwrite the non-key column values in the
main table with the values from the staging table.

Can any of you kindly share how this can be done most efficiently as I
would have more than 2 million records in the staging table and about
3 mill records in the main table at any point of time.

Thanks
Karen

Reply With Quote
  #2  
Old   
Uri Dimant
 
Posts: n/a

Default Re: Best and efficient way of overwriting a existing record in a table - 11-10-2004 , 04:57 AM






Karen

Use UPDATE StTable SET col1=MainTable.col1
FROM MainTable JOIN StTable ON MainTable.PK=StTable.PK






"Karen Middleton" <karenmiddleol (AT) yahoo (DOT) com> wrote

Quote:
I am loading data from one table to another the structure of both the
tables are the same.

When I copy from the staging table to the main table I want the
staging table records to overwrite the records with the same key in
the main table.

So for example the following are the keys in both tables:

Key columns
===========
Month
Material
Year
Customer
Store

Non-Key Columns
===============
SalesQty
Sales$

If the staging table as a record with the same key columns values as
the main table I want to overwrite the non-key column values in the
main table with the values from the staging table.

Can any of you kindly share how this can be done most efficiently as I
would have more than 2 million records in the staging table and about
3 mill records in the main table at any point of time.

Thanks
Karen



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.