Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Best way to right this insert query

Author  Topic 

kory27
Starting Member

35 Posts

Posted - 2008-05-01 : 22:43:08
Hi. I have 2 tables, this structure (basically);

Code Title
1 AAAAA
2 BBBBB
3 CCCCC
4 DDDDD

Code Title
1 AAAAA
2 BBBBB

Basically, what is the best method, ie. not in, left join, etc to write this insert query? I feel like I know this, but mostly I want to make sure I am using the most efficient way. There are 1.1M records in the first table, named Complete_Products, and 979K in tblProducts. I already ran the update query that selected on the ProductCode column in both that updated tblProduct for the records that were also in Complete_Products. That ran fine, a bit long, but it worked and updated the 805,273 records they had in common. Now I need to insert the new records that are in Complete_Products that are not in tblProducts.

Thanks so much for your help in advance.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-05-02 : 00:18:59
i'd use a left join.


elsasoft.org
Go to Top of Page

amrindia
Starting Member

8 Posts

Posted - 2008-05-02 : 01:16:47
Use Exists and Not Exists i.e Correlated Joins

MichaelRaj Arokiyasamy
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-02 : 02:10:57
I would have also done using the left join method
Go to Top of Page
   

- Advertisement -