1

I have a list of INSERTs, UPDATEs and DELETEs queries. My problem is that I always receive them in the wrong order (random), and I cannot know their original order.

Are there techniques to group/execute them in a particular order, so that I always end up with the roughly the same end-result as the source, no matter in which order I originally received them?

Maestro
  • 111
  • 2

1 Answers1

1

From your application layer, stamp each query with a timestamp and batch ID. Instead of executing the queries, store them in a temporary table with the format

sql_test | timestamp | batchID

When you know all queries from a batch have been received, kick off a stored proc that retrieves all queries from the batch, orders by timestamp asc and executes them

You'll probably want to add more logic about establishing dependencies between batches and how to deal with failed error,etc

Akash
  • 1,032
  • 1
  • 9
  • 25