I'm working on an SQL server database, containing orders and machines, executing those orders. Not more than one active order can be assigned to a machine at the same time. In other words: this SQL request can never yield a result:
SELECT MachineId
FROM Orders
WHERE (Orders.Status=1)
GROUP BY MachineId
HAVING COUNT(Id)>1
I have this SQL request open in a Microsoft SQL Server Management Studio environment, and every time I press F5, I indeed see no results.
However, I am sure that there have been times where that SQL query did yield results, and I'm interested in those times and the results of that query at those times.
Does anybody have an idea on how I can find this out? (The "archive-log" tag is just an idea)
Thanks in advance
MachineId
and when it assigns it to theOrders
table, so they are within the same transaction and occur atomically, which will block any other transaction from grabbing the sameMachineId
CONSTRAINT
or not? Or is it enforced by non-SQL application code - or not enforced at all? This rule should be trivial to implement using aUNIQUE
constraint - and once done means you won’t need to worry about this ever happening again.