<p>If I have a table where <strong>the cells in a column should not have the same values</strong>, how do I check this and update? (I know I can set constraints in the settings, but I don't want to do that.)</p>

<p>Say the column name is called <em>unique hash name</em> and contains </p>

<pre>
Peter
Peter
Peter
Dave
Dave
</pre>

<p>and so on. I want that to transform to:</p>

<pre>
Peter
Peter1
Peter2
Dave
Dave1
</pre>

<p>What is the T-SQL for SQL Server to do that?</p>

<p><strong>Update</strong>: For clarity's sake, let's call the table "Persons" and the cell I want unique "UniqueName". Could you make it a SELECT-statement, so I can test the result before updating. And I am using <strong>SQL Server 2005 and above</strong>.</p>

EDIT: I've changed the query to use your field names and added a "select-only" query for you to preview.
This is actually pretty easy to do... just use ROW_NUMBER() with a PARTITION clause:
```
```
UPDATE Persons SET UniqueName = temp.DeDupded FROM
    (SELECT ID,
        CASE WHEN ROW_NUMBER() OVER
            (PARTITION BY UniqueName ORDER BY UniqueName) = 1 THEN UniqueName
        ELSE UniqueName + CONVERT(VARCHAR, ROW_NUMBER()
            OVER (PARTITION BY UniqueName ORDER BY UniqueName)-1) END AS DeDupded
    FROM Persons) temp
WHERE Persons.ID = temp.ID
```
```
If you want a "select-only", then here you go:
```
```
SELECT ID,
    CASE WHEN ROW_NUMBER() OVER
        (PARTITION BY UniqueName ORDER BY UniqueName) = 1 THEN UniqueName
    ELSE UniqueName + CONVERT(VARCHAR, ROW_NUMBER()
        OVER (PARTITION BY UniqueName ORDER BY UniqueName)-1) END AS DeDupded
FROM Persons
```
```
EDIT Again: If you're looking for a SQL Server 2000 Solution...
```
```
CREATE TABLE #Persons ( ID INT IDENTITY(1, 1), UniqueName VARCHAR(100) )

INSERT INTO #Persons VALUES ('Bob')
INSERT INTO #Persons VALUES ('Bob')
INSERT INTO #Persons VALUES ('Bob')
INSERT INTO #Persons VALUES ('John')
INSERT INTO #Persons VALUES ('John')

SELECT
    ID,
    CASE WHEN Position = 0 THEN UniqueName
        ELSE UniqueName + (CONVERT(VARCHAR, Position))
    END AS UniqueName
FROM
    (SELECT
        ID,
        UniqueName,
        (SELECT COUNT(*) FROM #Persons p2 WHERE
            p1.UniqueName = p2.UniqueName AND p1.ID > p2.ID) AS Position
    FROM
        #Persons p1) _temp

DROP TABLE #Persons
```
```