mysql - Ensure values are not the same in a column -


i have table column values should not same. due poor implementation software not check ensure if user enters duplicate or not, therefore entrusted task of writing "simple" sql statement or function @ values in column , ensure not identical. sql executed once month not have efficient.

the column stores int , increment 1 of duplicate values, , keep on doing every time until there no more entries in table have same value column. suggestion should do? not sure start.

thanks insight.

edit: sorry forgot mention values in data not duplicate should stay way. these settings used customers, , should punish them if have duplicate values. if not, should not destroy settings or angry.

it 1 table, contains lot of columns, 1 specific column in particular of type int , never contains nulls, should not have duplicates.

 create table tablename (keycol int identity(1,1), intcol int)  insert tablename values (1), (2), (2), (3), (5), (6), (5), (7), (9)   while exists (     select intcol     tablename     group intcol     having count(*) > 1 ) begin      declare @newvalue int      select @newvalue = min(t1.intcol) + 1     tablename t1     left join tablename t2     on t1.intcol + 1 = t2.intcol     t2.intcol null      update tx     set intcol = @newvalue     tablename tx     intcol =      (select top 1 intcol     tablename t1     group intcol     having count(*) > 1     order intcol)     , keycol = (select min(keycol) tablename t2 t2.intcol = tx.intcol) end  select * tablename order 2 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -