just to complete the rrjegan17's post
for point number one you can achieve it by putting the dataset and passing it as xml to database
Main Topics
Browse All TopicsI have some data in a dataset. I need to check each row if it is already present in a database table having millions of records. What is the most efficient way of doing this?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> But I have a limitation of only running 'Select' statements on the database(cannot change the state of the database).
Then you have to loop through the records in your application.
No other go..
>> I need to check each row if it is already present in a database table having millions of records.
Since you mentioned your above limitation, can you explain your requirement in detail as I am not sure what you are trying to achieve..
Business Accounts
Answer for Membership
by: rrjegan17Posted on 2009-11-03 at 22:18:04ID: 25736861
>> I need to check each row if it is already present in a database table having millions of records.
Since you have Millions of records,
1. Insert records from your dataset into a temp table.
2. Run a query to find records that are present only in your temp table compared to the actual table like
select temp.pk
from temp left outer join ur_table on temp.pk = ur_table.pk
WHERE ur_table.pk is null
3. Above query would list records that are present newly in your temp table ( dataset)..
4. Insert records above only.
5. Update rest of the records if required.