• The code is as simple as that.

    declare @cnt Int,

    @max-2 Int

    declare @t TABLE (somekey Int identity(1,1) primary key, someval varchar (100))

    insert @t (someval)

    select blah from table1 <-- about 1000 rows.

    --Following avoids using cursors:

    SET @cnt = 1

    SET @max-2 = (select max(somekey) from @t)

    WHILE @cnt < @max-2

    BEGIN

    --Do some other update here.

    SET @cnt = @cnt + 1

    END

    The fact is, if the table var has "primary key" set on the key (which honestly isn't really needed since its a table in memory), the sproc hangs (I let it run for about a 1/2 an hour). If you remove primary key from the table def, it runs in about 40ms.

    I just wondered why this would make a difference. I've already learned my lesson and I'm not going to use that construct anymore. I just wondered why, thats all.

    Paul