I have a situation where I need to get a series of objects from two different SQL Server databases for the same period of time.
So if DB1 has a Car table, and DB2 has a Person table, I want to get all Cars and Persons up to a point in time t.
However, I’d prefer not to be dealing with dates (I don’t want to be encountering leap second issues and that kind of thing), and fortunately both databases use RowVersion columns. Ideally I’d like to use something like this RowVersion as a concurrency token (my t) representing a point in time / particular global state, that I could then compare records against.
Unfortunately, RowVersion columns are relative to a database, and so not comparable between different databases.
Is there a better solution here? Am I overreacting to not wanting to use dates?
Suggestions appreciated 🙂
Because you are talking about multiple separate systems, your options are unfortunately limited. You’ve started in the right place by storing all datetimes in GMT.
Beyond that,
datetimeis really the only appropriate data type to use here. Yes, it will be off between the multiple systems, by fractions of a second, assuming a good, common time sync. But simple network latency when updating records would also cause time differences, anyway, even if the clocks were exactly synced.RowVersioncan not help you, for the reason you have noted.The only other way would be to have a ‘sync’ table in one or the other database, which relates (logically, not ‘physically’) to records in either database, and has a common datetime or rowversion that you can use. That would increase the complexity of your querying a little bit, but you already seem to be doing cross-database queries, anyway.