title: Update Large Number of rows in sql server
body: <p>I'm trying to update a column in a table which has ~90,000 rows. Is there is any optimized way to update the table?</p>
  
  <p>I have added necessary indexes.. so that no table scans/lookups are not happening. But still it takes much time to run (1hr).</p>
  
  <p>My scenario:</p>
  
  <pre><code>DECLARE @ParentID   NVARCHAR(100),
          @Con_ERID   INT
  
  DECLARE @MaxCount   INT, 
          @MinCount   INT, 
          @Id         INT
  
  SELECT @MaxCount = MAX(Id) from [dbo].[ParentIDStaging] where Type='grid'
  
  SET @MinCount = 1
  
  WHILE @MinCount &lt;= @MaxCount 
  BEGIN
  
  SELECT @Id = ConID FROM [dbo].[ParentIDStaging] WHERE Id = @MinCount  and Type = 'grid'
  
  IF @Id IS NOT NULL
  BEGIN
  
  SELECT  @Con_ERID   =   ErId    FROM Context (NOLOCK) Where ConId = @Id
  SELECT  @ParentID   =   Identifier FROM Recording (NOLOCK) where ErId = @Con_ERID
  
      BEGIN TRAN
  
          UPDATE  [ParentIDStaging]       WITH (ROWLOCK)
          SET [ParentID]   = @ParentID
          WHERE   ContentType = 'grid'
          AND ConID   = @Id
  
      COMMIT
  END
  
  SET @MinCount = @MinCount + 1
  END
  </code></pre>