Update duplicate varchars to be unique in SQL database -


I need to change a database to add a unique barrier to the table column, but in this VARCHAR data is not unique.

How can I update those duplicate records so that each value is unique by adding sequential numbers at the end of the existing data?

For example, I use 'name1', 'name2', 'name3'

Want to change the SQL MS MS SQL Server 2 examples with using the taste here.

Setup Example:

  Create a table test (id int identity primary key, valve negotiation (20)) - - A is a PK for the ad cursor, Current "- name is not duplicated - name is duplicated 3 times - name c has been duplicated twice ('name') Enter test value Insert test value ('name' ') The inserted test value (' name ') is the inserted test value (' name 'B). Enter the value of the enrollment value ('name'). Enter the test value ('name')  

Sql 2005 \ 2008: (Computed Table Expression)

  get started Tran; - Quantity is required before the calculated table expires with expression; Partiton is important with the CAT (val, line) line above (wall, row_number ()) (row by wall order by wall). It reset the line_number with a new value where in Val (calculation of return value only Val)> 1) Cte set val = val + lectum (str (line)) - LTRIM (str (line)) = By converting into a string, the selected wall is repeated from the test group of the valve and remove the padding with the string command. * Test rollback with  

Choose Sql 2000: (cursor example)

  Declare the trick @root, @last varchar (20), @ search Declare the dupes cursor to select Val from test @last = '' where the value of the calculation of the value of the valve from the test group (Val) & gt; 1) Is updated by Val for Val's Open Dups to get from Duplex to the next @ while @@ fetch_status = 0 starts - a set of new approaches, as in 2005, if split with @last! = @ Current set @row = 1 update test - @ Val = val + ltrim (str (@row)) being set during the last update statement, @last = val where the current set is set @row = @row + Go ahead of duplue @ Duplex Deplus in @ Circuit and Close Dups * Select from the test rollback  

I rolled every update because both e xamples in my script file. This allowed me to test the functionality without resetting the rows on the table.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -