SQL 全局临时表中数据的持续时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5017641/
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
Duration of data in a Global Temporary table?
提问by Avi
Can someone please tell me: how long will data be there in a Global Temporary table?
有人可以告诉我:全局临时表中的数据会保留多长时间?
回答by Gabriel Magana
They can be SESSION based (data survives a commit but not a disconnect/reconnect). They can also be TRANSACTION based (data disappears after a commit).
它们可以是基于 SESSION 的(数据在提交后仍然存在,但在断开/重新连接时不会存在)。它们也可以基于 TRANSACTION(提交后数据消失)。
This creates a transaction based temp table:
这将创建一个基于事务的临时表:
create global temporary table temp_table_transaction on commit delete rows ...
This creates a session based temp table:
这将创建一个基于会话的临时表:
create global temporary table temp_table_transaction on commit preserve rows ...
回答by Vincent Malgrat
When you create a temporary tableyou have two optionsfor data persistence:
ON COMMIT DELETE ROWS
(default) andON COMMIT PRESERVE ROWS
ON COMMIT DELETE ROWS
(默认)和ON COMMIT PRESERVE ROWS
If you don't specify a persistence clause, or specify ON COMMIT DELETE ROWS
, the data in the table will be transaction-specific (it will be deleted upon commit or rollback).
如果不指定持久性子句或指定ON COMMIT DELETE ROWS
,则表中的数据将是特定于事务的(在提交或回滚时将被删除)。
If you specify ON COMMIT PRESERVE ROWS
, the data will stay until the end of your session.
如果指定ON COMMIT PRESERVE ROWS
,则数据将保留到会话结束。
回答by R Graves
If the table was created with "on commit preserve rows" then data will remain until the end of the current session. If it was created with "on commit delete rows" then it will remain until the next commit or rollback.
如果表是使用“提交时保留行”创建的,那么数据将保留到当前会话结束。如果它是使用“提交时删除行”创建的,那么它将一直保留到下一次提交或回滚。