We have table name and
How can we
SELECT all rows
INSERTed/UPDATEd in current transaction in
MS SQL Server?
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;
txid_current() is analogue of
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?