We have table name and CURRENT_TRANSACTION_ID().
How can we SELECT all rows INSERTed/UPDATEd in current transaction in MS SQL Server?
For example,
BEGIN TRANSACTION;
EXEC some_big_procedure();
--How to know what has been done inside some_big_procedure()?
ROLLBACK;
Note: original purpose is to test functions by comparing changes made by them with expected changes.
PostgreSQL has such mechanism (see this question):
BEGIN TRANSACTION;
SELECT some_big_procedure();
SELECT 'Changed row', t.*
FROM my_table t
WHERE t.xmin::text = (txid_current() % (2^32)::bigint)::text;
ROLLBACK;
Here txid_current() is analogue of CURRENT_TRANSACTION_ID(), t.xmin is built-in system column contains id of transaction which handles this row.
Bad solution is to write service function which will go through all the tables and add t.xmin's analogue. This column must be handled by triggers which are created dynamically by that service function too.
Any better idea for MS SQL?
some_big_procedure(). And what if we need to test output from 100 big procedures? Sorry, solution from question will be faster to implement. – Evgeny Nozdrev Oct 17 '18 at 09:55