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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:44:18+00:00 2026-05-30T02:44:18+00:00

The scenario I’ve got two tables with identical structure. TABLE [INFORMATION], [SYNC_INFORMATION] [ITEM] [nvarchar](255)

  • 0

The scenario

I’ve got two tables with identical structure.

TABLE [INFORMATION], [SYNC_INFORMATION]

    [ITEM] [nvarchar](255) NOT NULL
    [DESCRIPTION] [nvarchar](255) NULL
    [EXTRA] [nvarchar](255) NULL
    [UNIT] [nvarchar](2) NULL
    [COST] [float] NULL
    [STOCK] [nvarchar](1) NULL
    [CURRENCY] [nvarchar](255) NULL
    [LASTUPDATE] [nvarchar](50) NULL
    [IN] [nvarchar](4) NULL
    [CLIENT] [nvarchar](255) NULL

I’m trying to create a synchronize procedure that will be triggered by a scheduled event at a given time every day.

CREATE PROCEDURE [dbo].[usp_SynchronizeInformation]
AS
BEGIN
    SET NOCOUNT ON;

    --Update all rows
    UPDATE TARGET_TABLE
    SET TARGET_TABLE.[DESCRIPTION] = SOURCE_TABLE.[DESCRIPTION],
        TARGET_TABLE.[EXTRA] = SOURCE_TABLE.[EXTRA],
        TARGET_TABLE.[UNIT] = SOURCE_TABLE.[UNIT],
        TARGET_TABLE.[COST] = SOURCE_TABLE.[COST],
        TARGET_TABLE.[STOCK] = SOURCE_TABLE.[STOCK],
        TARGET_TABLE.[CURRENCY] = SOURCE_TABLE.[CURRENCY],
        TARGET_TABLE.[LASTUPDATE] = SOURCE_TABLE.[LASTUPDATE],
        TARGET_TABLE.[IN] = SOURCE_TABLE.[IN],
        TARGET_TABLE.[CLIENT] = SOURCE_TABLE.[CLIENT]
    FROM SYNC_INFORMATION TARGET_TABLE 
        JOIN LSERVER.dbo.INFORMATION SOURCE_TABLE ON TARGET_TABLE.ITEMNO = SOURCE_TABLE.ITEMNO
    WHERE TARGET_TABLE.ITEMNO = SOURCE_TABLE.ITEMNO

    --Add new rows
    INSERT INTO SYNC_INFORMATION (ITEMNO, DESCRIPTION, EXTRA, UNIT, STANDARDCOST, STOCKTYPE, CURRENCY_ID, LASTSTANDARDUPDATE, IN_ID, CLIENTCODE)
    SELECT 
        src.ITEM, 
        src.DESCRIPTION,
        src.EXTRA,
        src.UNIT,
        src.COST,
        src.STOCKTYPE,
        src.CURRENCY_ID,
        src.LASTUPDATE,
        src.IN,
        src.CLIENT
    FROM LSERVER.dbo.INFORMATION src
        LEFT JOIN SYNC_INFORMATION targ ON src.ITEMNO = targ.ITEMNO
    WHERE
        targ.ITEMNO IS NULL
END

Currently, this procedure (including some others that are also executed at the same time) takes about 15 seconds to execute.
I’m planning on adding a “Synchronize” button in my work interface so that users can manually synchronize when, for instance, a new item is added and needs to be used the same day.

But in order for me to do that, I need to trim those 15 seconds as much as possible.


Instead of updating every single row, like in my procedure, is it possible to only update rows that have values that does not match?
This would greatly increase the execution speed, since it doesn’t have to update all the 4000 rows when maybe only 20 actually needs it.

Can this be done in a better way, or optimized?
Does it need improvements, if yes, where?

How would you solve this?

Would also appreciate some time differences between the solutions so I can compare them.

UPDATE

Using marc_s’s CHECKSUM is really brilliant. The problem is that in some instances the information creates the same checksum. Here’s an example, due to the classified content, I can only show you 2 columns, but I can say that all columns have identical information except these 2. To clarify: this screenshot is of all the rows that had duplicate CHECKSUMs. These are also the only rows with a hyphen in the ITEM column, I’ve looked.

enter image description here

The query was simply

SELECT *, CHECKSUM(*) FROM SYNC_INFORMATION
  • 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-30T02:44:19+00:00Added an answer on May 30, 2026 at 2:44 am

    If you can change the table structure ever so slightly – you could add a computed CHECKSUM column to your two tables, and in the case the ITEM is identical, you could then check that checksum column to see if there are any differences at all in the columns of the table.

    If you can do this – try something like this here:

    ALTER TABLE dbo.[INFORMATION]
      ADD CheckSumColumn AS CHECKSUM([DESCRIPTION], [EXTRA], [UNIT],
                                     [COST], [STOCK], [CURRENCY],
                                     [LASTUPDATE], [IN], [CLIENT]) PERSISTED
    

    Of course: only include those columns that should be considered when making sure whether a source and a target row are identical ! (this depends on your needs and requirements)

    This persists a new column to your table, which is calculated as the checksum over the columns specified in the list of arguments to the CHECKSUM function.

    This value is persisted, i.e. it could be indexed, too! :-O

    Now, you could simplify your UPDATE to

     UPDATE TARGET_TABLE
     SET ......
     FROM SYNC_INFORMATION TARGET_TABLE 
     JOIN LSERVER.dbo.INFORMATION SOURCE_TABLE ON TARGET_TABLE.ITEMNO = SOURCE_TABLE.ITEMNO
     WHERE 
         TARGET_TABLE.ITEMNO = SOURCE_TABLE.ITEMNO
         AND TARGET_TABLE.CheckSumColumn <> SOURCE_TABLE.CheckSumColumn
    

    Read more about the CHECKSUM T-SQL function on MSDN!

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

Sidebar

Related Questions

Scenario: Let's say I have two tables, TableA and TableB. TableB's primary key is
Scenario I have two wrappers around Microsoft Office, one for 2003 and one for
Scenario You've got several bug reports all showing the same problem. They're all cryptic
Scenario I have a 10 million row table. I partition it into 10 partitions,
Scenario : i have a database table that is being updated frequently by some
Scenario: I have a Question which has 2 radio buttons & two subforms: subformA
Scenario: Delphi did a non-normal shutdown. When I restarted I got the messages Could
Scenario: Repository structure changed from /trunk/ to /projectName/trunk/ and the local copy is outdated
Scenario: I have got a client, php script and a MySQL database. I am
Scenario 1: Table: id column1 column2 1 bla foo 2 bla bar I want

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.