If I have a table where the cells in a column should not have the same values, how do I check this and update? (I know I can set constraints in the settings, but I don’t want to do that.)
Say the column name is called unique hash name and contains
Peter Peter Peter Dave Dave
and so on. I want that to transform to:
Peter Peter1 Peter2 Dave Dave1
What is the T-SQL for SQL Server to do that?
Update: 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 SQL Server 2005 and above.
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:
If you want a ‘select-only’, then here you go:
EDIT Again: If you’re looking for a SQL Server 2000 Solution…