Tag Info

New answers tagged

0

This shouldn't be right, should it? It's right. Databases (not just MySQL) generally ensure that sequences will only ever increase (once a transaction is committed), but not that they will be without gaps. For instance, TFM says: You may see gaps in the sequence of values assigned to the AUTO_INCREMENT column if you roll back transactions that have ...


1

You can create a new table like the old one and insert the values in a different order, for example: CREATE TABLE new_table like old_table; INSERT INTO new_table (date, name) SELECT date, name FROM old_table ORDER BY date ASC, id DESC Change the ORDER BY to whatever suits to you- I have ordered by date so it doesn't trust that the original data was ...


0

Nevermind. I used mysqli_insert_id and it worked. The documentation for this solution is available here.


0

I know my answer might be late. Yes, this used to happen when SQL server is restarted. See here for more information (as given in other answers). With SQL Server 2014, it has been fixed (identity wont increased by 1000) only if there was a planned SQL Server restart. I have solved in another way by adding a start up stored procedure in SQL Server 2012. ...


-4

If you only need to eliminate the last rows which have not followed the incremental value of an identity field, there is an easy and safe way: first delete the last record(s) which have 'jumped' change the data type of your Identity Field (from int to bigint or vice versa) save the table add a new record, and check it assigns the number of the highest ...



Top 50 recent answers are included