How to inspect SQL Server database during a transaction?
I'm trying to debug part of an appl开发者_高级运维ication where a number of actions on the database are taking place inside the same transaction, with the later steps depending on the ones completed before. It would be useful to be able to take a look at what's going on in the database, to make sure each step is being completed correctly.
Is there a way to take a look at what's in the database while a transaction is running?
SELECT * FROM dbo.Table WITH (NOLOCK)
will do what your looking for, just be careful of phantom reads.
If you mean that you want to look at table data (an assumption on my behalf) you can always use the the WITH (NOLOCK)
constraint on the table - but I am not certain you'll get anything that has been modified in your transaction.
If you want to know which SQL statements are being executed use SQL Server Profiler
An extension of the WITH (NOLOCK)
idea expressed in other answers... You could simply:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
Which would then allow you to "snoop" into data that has not yet been committed by the transaction being debugged. This is very useful if you need to call stored procedures or functions, which cannot be directly subjected to WITH (NOLOCK)
.
精彩评论