手动将数据插入到主键填充序列的表中
我有许多表使用触发器/序列列来模拟主键上的自动增量,这在一段时间以来效果很好。
为了加快对使用数据库的软件执行回归测试所需的时间,我使用一些示例数据创建控制文件,并将这些文件的运行添加到构建过程中。
尽管测试过程从头开始安装架构,并且序列返回表中已存在的值,但此更改导致大多数测试崩溃。 有没有办法以编程方式说“将序列更新为列中的最大值”,或者我是否需要手动编写一个完整的脚本来更新所有这些序列,或者我/应该更改用空值替换空值的触发器吗?序列到如何检查这一点(尽管我认为这可能会导致变异表问题)?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作为架构重建的一部分,为什么不删除并重新创建序列呢?
As part of your schema rebuild, why not drop and recreate the sequence?
下面是更新序列值的简单方法 - 在本例中,如果序列当前为 50,则将序列设置为 1000:
感谢 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:
Kudos to the creators of PL/SQL Developer for including this technique in their tool.
您可以生成一个脚本来创建具有所需起始值的序列(基于其现有值)....
(如果我正确理解问题)
You can generate a script to create the sequences with the start values you need (based on their existing values)....
(If I understand the question correctly)