Mysql regenerate missing IDs from 1 to N -


I have a table with indexed column id2 . After using this table to insert / delete records, there are some missing records. id2 starts this way

1,2,3,4,8,9,13,55,66,67,68 .... 928746 < / P>

How can I regenerate the sequence of id2 , so the missing number [1,2,3,4,5,6. ..] is not? In addition, the id2 must be in line with the ts field, which is the Unix timestamp for record insertion.

Is it possible to do this with mysql query, without any code (PHP)?

PS Anything depends on these IDs I can change them independently, do I just want to do any signals?

  SET @ rownum = 0; Update [Table] T, (SELECT @rownum: = @ rownum + 1 rownum, [table]. * From [table]) R set t. [Field] = R.Province where WHERE (T. [primary_key] = R. [primary_key])   

replace [table] with your table name, [field] by your field name , And [primary_key] from the primary key column name

to:

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -