Here's a little sql 2005 script I wrote:
1. Start by running this script....
declare @.x int
select @.x = 1
while ( @.x < 75000)
begin
insert into myTesttable values (@.x)
Select @.x = @.x + 1
end
2. While the script is still running, I want to know how many records are in the table. From the same query window as the script, I have run both of the following statements.
select count(*) from mytesttable
witn (nolock)
select count(*) from mytesttable
witn (tablock)
Instead of getting the answer immediately, they run only after the original script has completed. They seem to be "blocked". How can I get a near realtime count of the number of records in this table while the script populates the table?
Thanks,
Barkingdog
Barkingdog, just open another query window and run your "select count(*) from mytesttable". You'll get the row count while the other script is running.|||If you use GridView it only displayed after the batch execution completed.
You can use different window or change the GridView to TextView to get the result immd.
|||Yes, opening a new window did enable to the "select count(*) ...." to run but why is this the case? (After all, I couldn't run the "Select count(*) .." from the window that invoked the original script. Seems like the orignal script "blocks" the conneciton so I need to open a new conneciton (window). But why?
TIA,
barkingdog
|||barkingdog wrote: Yes, opening a new window did enable to the "select count(*) ...." to run but why is this the case? (After all, I couldn't run the "Select count(*) .." from the window that invoked the original script. Seems like the orignal script "blocks" the conneciton so I need to open a new conneciton (window). But why?
TIA,
barkingdog
The query window runs the statements sequentially and does not run the next statement until the prior one has finished, thus your select count(*)... will not run until the statements in the while loop complete. It's not "blocking" the connection, it just has not completed the prior statements...
If one of the replies solved your problem, please mark them as answered...
No comments:
Post a Comment