September 10, 2012 at 5:08 pm
I have two identical tables. Table 1 has 12,000 rows and Table 2 has 11,000 rows. I need to insert rows from Table 2 on Table 1 that don’t exist on Table 1. What is a quick way of accomplishing this?
September 10, 2012 at 5:10 pm
Insert into Table1 (<column list>)
Select <columns> from Table2
WHERE <primary key column> NOT IN (select <primary key column> FROM Table1)
or
Insert into Table1 (<column list>)
Select <columns> from Table2
EXCEPT
Select <columns> from Table1
Roughly.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 10, 2012 at 5:15 pm
could also use something like:
insert into table1 (Values)
SELECT values
FROM table2
LEFT JOIN table1
ON table2.somecolumn = table1.somecolumn
WHERE table1.somecolumn IS NULL
at lease i think since we dont have DDL and Sample data its hard to get tested code
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
September 10, 2012 at 5:21 pm
September 10, 2012 at 5:58 pm
Mark Eckeard (9/10/2012)
Look at except:http://msdn.microsoft.com/en-us/library/ms188055.aspx
Mark
If you are going to post a url, at least make it usuable.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply