Skip to content
Advertisement

How to use CHECKSUM in a trigger

I’m trying to create my own logic for tables synchronization in SQL Server Express 2019. I was hoping that such simple task would work:

  1. Have a Customers table

  2. Have a Synchronization table

  3. Have a trigger on Customers:

… but I got an error about the SELECT CHECKSUM(*) FROM inserted part:

Cannot use CHECKSUM(*) in a computed column, constraint, default definition, or INSERT statement.

Is there any other way to add new Customer‘s CHECKSUM or some hash to the Synchronization table?

Advertisement

Answer

Don’t use the VALUES syntax when inserting and you won’t get an error using CHECKSUM while inserting.

Example:

Implementing the concept in your trigger:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement