sequencing

How do I reset sequence numbers to become consecutive?

岁酱吖の 提交于 2019-11-29 10:23:20
I've got a mysql table where each row has its own sequence number in a "sequence" column. However, when a row gets deleted, it leaves a gap. So... 1 2 3 4 ...becomes... 1 2 4 Is there a neat way to "reset" the sequencing, so it becomes consecutive again in one SQL query? Incidentally, I'm sure there is a technical term for this process. Anyone? UPDATED: The "sequence" column is not a primary key. It is only used for determining the order that records are displayed within the app. If the field is your primary key... ...then, as stated elsewhere on this question, you shouldn't be changing IDs.

How do I reset sequence numbers to become consecutive?

走远了吗. 提交于 2019-11-28 03:47:26
问题 I've got a mysql table where each row has its own sequence number in a "sequence" column. However, when a row gets deleted, it leaves a gap. So... 1 2 3 4 ...becomes... 1 2 4 Is there a neat way to "reset" the sequencing, so it becomes consecutive again in one SQL query? Incidentally, I'm sure there is a technical term for this process. Anyone? UPDATED: The "sequence" column is not a primary key. It is only used for determining the order that records are displayed within the app. 回答1: If the