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 7531417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:09:58+00:00 2026-05-30T05:09:58+00:00

I am trying to using a SQL data reader to move records from one

  • 0

I am trying to using a SQL data reader to move records from one table into an archive table. I want to do the transfer record-by-record (instead of inserting and deleting en masse) so that if an error occurs, the minimum amount of data is lost (and has to be restored from backup).

My question is, will SQL reader work if I delete records once they are read? This is by far the most simple and direct way to do what I am trying to do. Will it open unexpected errors?

While myReader.Read // select * from tableA where older than 1 year record
    insert the record into tableA_archive
    delete the record from tableA   
loop

This seems vaguely analogous to looping through a list that you are modifying within the loop–which I know causes all sorts of headaches in .net

for aItem in listA
   if aItem fits criteria, send to list B and delete from listA
next

Is there any reason not to modify the underlying table while a reader is reading? For instance, does a reader use certain indexes to reach records that might shift if I start deleting records in the middle of the loop?

  • 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-30T05:09:59+00:00Added an answer on May 30, 2026 at 5:09 am

    You should avoid transferring rows all the way down to the client, just to re-upload them back to the server again. Instead, do something like this (within the same transaction):

    INSERT INTO NEW_TABLE SELECT * FROM OLD_TABLE WHERE condititon;
    DELETE FROM OLD_TABLE WHERE condititon;
    

    Or even MS SQL Server specific:

    DELETE FROM OLD_TABLE OUTPUT DELETED.* INTO NEW_TABLE WHERE condition;
    

    (all conditions are same)

    You can even execute these statements from your .NET code if you wish, and still retain the benefit of not downloading all the rows.

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

Sidebar

Related Questions

I am trying to copy data from my MYSQL table to SQL Server using
I'm trying to read data from SQL Server database using Perl and the DBI
I'm trying to read data from Google Fusion Tables API into Python using the
I'm trying to pull data using a SqlDataReader, one column of which is in
In the last few days I am trying to get data from my SQL
I'm using C# and .NET 3.5, trying to import some data from old dbf
Ok guys, so I am trying to bind data into a dropdown list from
I am trying to connect to the SQL Server from Visual Web Developer using
I am using a SqlDataReader and I am trying to read from a table
I'm new to ASP. I am trying to insert data from an asp:textbox into

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.