手动将数据插入到主键填充序列的表中

发布于 2024-07-05 01:28:15 字数 277 浏览 8 评论 0原文

我有许多表使用触发器/序列列来模拟主键上的自动增量,这在一段时间以来效果很好。

为了加快对使用数据库的软件执行回归测试所需的时间,我使用一些示例数据创建控制文件,并将这些文件的运行添加到构建过程中。

尽管测试过程从头开始安装架构,并且序列返回表中已存在的值,但此更改导致大多数测试崩溃。 有没有办法以编程方式说“将序列更新为列中的最大值”,或者我是否需要手动编写一个完整的脚本来更新所有这些序列,或者我/应该更改用空值替换空值的触发器吗?序列到如何检查这一点(尽管我认为这可能会导致变异表问题)?

I have a number of tables that use the trigger/sequence column to simulate auto_increment on their primary keys which has worked great for some time.

In order to speed the time necessary to perform regression testing against software that uses the db, I create control files using some sample data, and added running of these to the build process.

This change is causing most of the tests to crash though as the testing process installs the schema from scratch, and the sequences are returning values that already exist in the tables. Is there any way to programtically say "Update sequences to max value in column" or do I need to write out a whole script by hand that updates all these sequences, or can I/should I change the trigger that substitutes the null value for the sequence to some how check this (though I think this might cause the mutating table problem)?

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

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

发布评论

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

评论(3

桃扇骨 2024-07-12 01:28:15

作为架构重建的一部分,为什么不删除并重新创建序列呢?

As part of your schema rebuild, why not drop and recreate the sequence?

花开雨落又逢春i 2024-07-12 01:28:15

下面是更新序列值的简单方法 - 在本例中,如果序列当前为 50,则将序列设置为 1000:

alter sequence MYSEQUENCE increment by 950 nocache;
select MYSEQUENCE_S.nextval from dual;
alter sequence MYSEQUENCE increment by 1;

感谢 PL/SQL Developer 的创建者在他们的工具中包含此技术。

Here's a simple way to update a sequence value - in this case setting the sequence to 1000 if it is currently 50:

alter sequence MYSEQUENCE increment by 950 nocache;
select MYSEQUENCE_S.nextval from dual;
alter sequence MYSEQUENCE increment by 1;

Kudos to the creators of PL/SQL Developer for including this technique in their tool.

李白 2024-07-12 01:28:15

您可以生成一个脚本来创建具有所需起始值的序列(基于其现有值)....

SELECT 'CREATE SEQUENCE '||sequence_name||' START WITH '||last_number||';'
FROM   ALL_SEQUENCES
WHERE  OWNER = your_schema

(如果我正确理解问题)

You can generate a script to create the sequences with the start values you need (based on their existing values)....

SELECT 'CREATE SEQUENCE '||sequence_name||' START WITH '||last_number||';'
FROM   ALL_SEQUENCES
WHERE  OWNER = your_schema

(If I understand the question correctly)

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