JavaDB:是否可以更改现有表的自动增量偏移量?

发布于 2024-07-10 05:10:32 字数 262 浏览 5 评论 0原文

是否可以使用 JavaDB 更改预先存在的表上的自动增量偏移量?

我遇到的问题是,插入新记录通常(但并非总是)失败,并出现错误,抱怨使用现有键(我的自动增量列)。 为了填充此数据库,我从另一个数据库 (MySQL) 获取转储,并使用 JavaDB 存储过程将它们全部插入到相应的 JavaDB 表中。 我的理论是,插入这些记录会复制 MySQL 表中的现有 ID。 现在,自动增量功能正在分发现有的 ID。 我认为明确地将偏移量设置为某个较高的数字将允许自动增量再次起作用。

Is it possible to change the auto-increment offset on a pre-existing table with JavaDB?

I'm having a problem where inserting new records usually (but not always) fails with an error complaining about using an existing key (my auto-increment column). To populate this database, I took a dump from another database (MySQL) and used a JavaDB stored procedure to insert them all into the corresponding JavaDB table. My theory is that inserting these records copied the existing IDs from the MySQL table. Now the auto-increment functionality is dishing out existing IDs. I figure explicitly setting the offset to some high number will allow the auto-increment to work again.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三人与歌 2024-07-17 05:10:33

即使这不是问题的直接答案:
使用MySQL,您可以

ALTER TABLE my_little_table AUTO_INCREMENT =2000

设置自动增量值。

Even if it's not a direct answer to the question:
With MySQL, you can do a

ALTER TABLE my_little_table AUTO_INCREMENT =2000

to set the auto increment value.

暖伴 2024-07-17 05:10:33

我不知道如何直接更改偏移量,但我设法通过以下方式解决此问题:

  1. 将增量金额更改 X(在我的例子中为 100 万)。
  2. 插入虚拟记录。
  3. 将增量减少回 1。
  4. 删除虚拟记录。

我使用这个SQL语句来改变增量数量:

ALTER TABLE tbl ALTER COLUMN col SET INCREMENT BY x

I don't know how to directly change the offset, but I managed to fix this by:

  1. Changing the increment amount by X (1 million in my case).
  2. Inserting a dummy record.
  3. Reducing the increment amount back down to 1.
  4. Deleting the dummy record.

I used this SQL statement to change the increment amount:

ALTER TABLE tbl ALTER COLUMN col SET INCREMENT BY x
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文