title: How to update a column with ROW_NUMBER() in SQL
body: <p>I have added a new column to the table. Now i want to update this column with values from the function row_number().And i want to do it because i want to remove duplicate entries.  The below mentioned code is not giving the desired output</p>
  
  <pre><code>UPDATE tab1
  SET rownumber = (SELECT ROW_NUMBER() OVER(ORDER BY name ASC) 
               FROM tab1 AS a WHERE a.name = b.name)
  FROM tab1 b
  </code></pre>
  
  <p>Problem is that when a new column is added in a table its values are null. Insert into adds new rows in the table but does not replace nulls. How to update null values with row numbers generated by function ROW_NUMBER().</p>
  
  <p>The below mentioned table is what i have    </p>
  
  <p><strong>name          score</strong></p>
  
  <p>Bank of America 10</p>
  
  <p>Commerce Bank   20</p>
  
  <p>Wells Fargo Bank    135</p>
  
  <p>Bank Midwest    45</p>
  
  <p>Bank of America 10</p>
  
  <p>Commerce Bank   20</p>
  
  <p>now I want the output as after removing the duplicates  </p>
  
  <p><strong>name          score</strong></p>
  
  <p>Bank of America 10</p>
  
  <p>Commerce Bank   20</p>
  
  <p>Wells Fargo Bank    135</p>
  
  <p>Bank Midwest    45</p>
  
  <p>I was trying to add a new column with unique values to get the desired result.  </p>