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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:32:47+00:00 2026-05-11T10:32:47+00:00

I am looking for a way to quickly compare the state of a database

  • 0

I am looking for a way to quickly compare the state of a database table with the results of a Web service call.

I need to make sure that all records returned by the Web service call exist in the database, and any records in the database that are no longer in the Web service response are removed from the table.

I have to problems to solve:

  1. How do I quickly compare a data structure with the results of a database table?
  2. When I find a difference, how do I quickly add what’s new and remove what’s gone?

For number 1, I was thinking of doing an MD5 of a data structure and storing it in the database. If the MD5 is different, then I’d move to step 2. Are there better ways of comparing response data with the state of a database?

I need more guidance on number 2. I can easily retrieve all records from a table (SELECT * FROM users WHERE user_id = 1) and then loop through an array adding what’s not in the DB and creating another array of items to be removed in a subsequent call, but I’m hoping for a better (faster) was of doing this. What is the best way to compare and sync a data structure with a subset of a database table?

Thanks for any insight into these issues!

  • 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. 2026-05-11T10:32:47+00:00Added an answer on May 11, 2026 at 10:32 am

    I’ve recently been caught up in a similar problem. Our–very simple–solution was to load the web service data into a table with the same structure as the DB table. The DB table keeps a hash of its most important columns, and the same hash function is applied to the corresponding columns in the web service table.

    The ‘sync’ logic then goes like this:

    1. Delete any rows from the web service table with hashes that do exist in the DB table. This is duplicate data that doesn’t need synchronizing.

      DELETE FROM ws_table WHERE hash IN (SELECT hash from db_table);

    2. Delete any rows from the DB table with hashes not found in the web service table.

      DELETE FROM db_table WHERE hash NOT IN (SELECT hash FROM ws_table);

    3. Anything left over in the web service table is new data, and should now be inserted into the DB table.

      INSERT INTO db_table SELECT ... FROM ws_table;

    It’s a pretty brute-force approach, and if done transactionally (even just steps 2 and 3) locks up the DB table for the duration, but it’s very simple.

    One refinement would be to deal with changed records using UPDATE statements, but that adds a good deal of complexity, and may not be any faster than a DELETE followed by an INSERT.

    Another possible optimization would be to set a flag instead of deleting rows. The rows could then be deleted later on. However, any logic using the DB table would have to ignore rows with a set flag.

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

Sidebar

Related Questions

I'm looking for a way to quickly process some table in mysql 5.0.X. I'd
I am looking for a way to quickly determine if a PNG image has
My problem is that I was looking for way to use both storyboard and
I have been all over the web looking for a clean way to change
Long story short, I am looking for the best way to quickly and efficently
I'm looking for a way to insert royalty (or otherwise) free photos quickly into
I am looking for a way to quickly remove items from a C# List<T>
I'm looking a way to enable IP logging with log4net in ASP.NET. I found
I'm looking for way to write Javascript programs / scripts on desktop, not inside
I'm looking a way to build conditional assignments in bash: In Java it looks

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.