Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:08:09+00:00 2026-05-29T12:08:09+00:00

I have a scenario where data needs to be imported from a CSV file

  • 0

I have a scenario where data needs to be imported from a CSV file through a .NET application to SQL Server 2008 on a database server (distributed). The CSV file contains around 4 million ‘records’ while the destination table can contain over 100 million records. The data that is being imported needs to be checked against existing data for duplicates before the insert is done.

I tried building a DataTable in memory and sending this as a parameter to a stored procedure, however this is performing very badly.

What is a good approach for this scenario?

  • Data for import (importdata) needs to be sent to SQL Server
  • importdata needs to be checked agains existing data (existing) for duplicates
  • if just a single duplicate is found in existing the entire import for importdata needs to be aborted

CSV Format

"Name1", "11111111-1111-1111-1111-111111111111"
"Name1", "11111111-1111-1111-1111-111111111111"
"Name1", "11111111-1111-1111-1111-111111111111"

Data for import (DataTable format schematically):

Table (
    name nvarchar(20),
    someId uniqueidentifier
)

Destination table on SQL Server (schematically):

Table (
    id int primarykey,
    name nvarchar(20),
    someId uniqueidentifier
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:08:09+00:00Added an answer on May 29, 2026 at 12:08 pm

    What I would do . . .

    1. Using the SqlBulkCopy class I’d insert the 4 million rows into the
      database into a temporary table (or a table that’s permanent but
      used only for this purpose).
    2. Write a Proc that runs one table against the other, and only inserts
      rows to destination table appropriately.

    The SqlBulkCopy class is by far the fastest way to get data into a MS SQL DB, and then get the db to do the update, it’s what it’s good at.

    Update Can this be done in a transaction?

    Yes, but I wouldn’t like to imagine a transaction covering the insertion of 4 million rows and updating a different 4 million rows.

    If you use a truly temporary table (e.g. #MyTempStrore) then the temp table will be dropped when you finish that session on the database (e.g. dbConn.Close()).
    If you use a permant table, you can create a unique session Id, insert all the rows with that Id and pass that Id to the stored proc. You can then clear those ids out of the table when you wish (or just truncate the table).

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario: Data from multiple video files needs to be held
Scenario I have an web application which needs some calculations and processing on data.
I have this scenario where I need data integrity in the physical database. For
we have this scenario: A server which contains needed data and client component which
I have the following scenario: I have various user's data stored in my database.
In general, I have the following scenario: Fetch product and its related data from
Scenario: old legacy code in rpg have to consume data from a new web
So this is the scenario: You have a bunch of data that needs to
Here is my scenario. I have an ASP.NET MVC solution with 3 projects. Data,
Scenario I've got an application written in C# that needs to dump some data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.