哪个命令将替换 Oracle 中 SQLServer 的 IDENTITY INSERT ON/OFF?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2758990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which command would replace IDENTITY INSERT ON/OFF from SQLServer in Oracle?
提问by rodrigoq
I have to migrate this query (simplified here) from T-SQL to ORACLE
我必须将此查询(此处简化)从 T-SQL 迁移到 ORACLE
SET IDENTITY_INSERT table ON
INSERT INTO table (id, value) VALUES (1, 2)
SET IDENTITY_INSERT table OFF
id
being an Identity field in SQLServer.
id
作为 SQLServer 中的标识字段。
I have the same table with a sequence in ORACLE, I couldn't find a snippet that shows how to disable the sequence and set it to start again with the MAX(id) + 1.
我在 ORACLE 中有一个带有序列的同一个表,我找不到一个片段来显示如何禁用该序列并将其设置为使用 MAX(id) + 1 重新开始。
Any ORACLE expert can help me with this?
有哪位 ORACLE 专家可以帮我解决这个问题吗?
Thanks, Rodrigo.
谢谢,罗德里戈。
采纳答案by MJB
You don't have to disable the identity in Oracle. Since you are using sequences, just don't use it for that insert.
您不必在 Oracle 中禁用身份。由于您正在使用序列,因此不要将其用于该插入。
That is, instead of
也就是说,而不是
insert into table (id, values) values (table_seq.nextval, 2)
you use
你用
insert into table (id, values) values (1, 2)
As to your second question about restarting the sequence, I think that is answered herein SO.
至于你关于重新启动序列的第二个问题,我认为这是回答了在这里的SO。
回答by DCookie
Messing with columns populated by Oracle sequences in this way seems like a Bad Idea. In Oracle, you are typically maintaining a column populated via sequences with a trigger. If you start turning this feature on and off, and resetting the sequence ad lib, you run the risk of a sequence not being available when another process needs it, or getting reset to a value that has been used already but not committed.
以这种方式处理由 Oracle 序列填充的列似乎是个坏主意。在 Oracle 中,您通常使用触发器维护通过序列填充的列。如果您开始打开和关闭此功能,并重置序列即兴库,您将面临序列在另一个进程需要时不可用的风险,或者被重置为已使用但未提交的值。
回答by Nate Zaugg
Drop the sequences and re-create them when you're done with the max+1 value.
删除序列并在完成 max+1 值后重新创建它们。