清理 Oracle 序列
我广泛使用 SQL Server,但对 Oracle 的经验很少。我接到的任务是“清理”Oracle 数据库中的序列,但我不知道如何安全地完成此任务。
我需要确定表中实际的最大值(假设 ID = 105)。然后查看该 ID 的下一个序列是什么。如果是106,那就万事大吉了。如果是 110,那么我需要将其重置回 106。
我可以安全地删除一个序列然后重新创建它,还是会弄乱已经存在的主键?我猜这不会是一个问题,但在我提升别人的系统之前,我想问一下。
这是我要使用的命令
Drop Sequence blah.foo_seq
Create Sequence blah.foo_seq Start WIth 106 Min 1 Max 2147483647 yada yada
I've worked extensively with SQL Server but have very little experience with Oracle. I've been given the task of "cleaning up" the Sequences in an Oracle database and am not sure how to go about this safely.
I need to determine the maximum value actually in the table (say the ID = 105). Then look and see what the next sequence for that ID is. If it is 106, then all would be good. If it were 110, then I need to reset it back to 106.
Can I safely drop a sequence then recreate it or will that muck up the already existing Primary Key? I'm guessing this wouldn't be a problem but before I jacked up someone else's system, I wanted to ask.
This is the command I am going to use
Drop Sequence blah.foo_seq
Create Sequence blah.foo_seq Start WIth 106 Min 1 Max 2147483647 yada yada
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常会对“清理”Oracle 序列的需要保持警惕。由于 Oracle 序列不能用于生成无间隙值,因此如果 110 会给应用程序带来问题,则需要解决更大的问题。
删除序列对主键没有影响。但它确实会使引用该序列的任何对象失效并删除任何特权授予。您可以在重新创建序列后重新编译代码,删除权限可能会出现问题。
避免处理丢失特权的另一种方法是更改 INCREMENT BY 参数以减小序列值,即
I'd generally be wary about the need to "clean up" an Oracle sequence. Since Oracle sequences cannot be used to generate gap-free values, if 110 would cause a problem for the application, there are bigger problems that need to be addressed.
Dropping a sequence has no impact on a primary key. But it does invalidate any objects that reference the sequence and remove any privilege grants. You can recompile the code after you've re-created the sequence, it's the dropping of the privileges that would be potentially problematic.
An alternative approach that avoids the need to deal with lost privileges would be to change the INCREMENT BY parameter to decrease the sequence value, i.e.