How can i retrieve data, when there is insertion in process? Suppose I created a Table: CREATE TABLE [dbo].[names]( [id] [int] NULL, [name] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL ) ON [PRIMARY] Then I ran command: Begin Tran insert into names values (1,’imran’) insert into names values (2,’one’) insert into names values (3,’two’) Then In opened a new window and tried the following command: select * from names It is hanged…. But this command is working fine…. select * from names with (nolock) But this command is also showing unsaved data…. Then If I moved to first window and execute commit or rollback then both commands in other window running fine… So My Question is how can i retrieve data, even if there is some insertion in process…. The problem is not for this table, for me the problem is, I have a table of almost one TB with index on four columns, and there is bulk insert after every one hour, so whenever the bulk insert is in process, in these 20 to 30min, I can only execute statements with nolock, why I cannot run without nolock keyword to see only committed data…
by Ari Weil
What you’re looking for is the READPAST table hint. READPAST tells the query to read the rows not blocked by a transaction. Read more on how READPAST works here.
Theoretically you could use SQL Server 2005’s READ COMMITTED SNAPSHOT isolation level, however you’d best be sure your TempDB is configured to handle the extra load…Read more on SNAPSHOT isolation here.
Tags: Programming