Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望允许在 sql 表中间插入行,然后自动将升序 id 更新为 +1。
例子:
ROW ID 1 5 2 6 3 7 4 8
然后我希望能够插入 id 为 6 的第 5 行,并使其他行更新为当前编号的 +1:
ROW ID 1 5 2 7 3 8 4 9 5 6
有没有一种有效的方法?除了遍历整个表格并将其他 id 调整为 +1 之外?
向ID列添加索引。这样,您只需要遍历实际受更新操作影响的行,而不是遍历整个表。不利的一面是,每个索引都会使插入变得更加昂贵。
ID
顺便说一句,如果该列属于您的主键,请不要更改ID条目。ID