简体   繁体   English

何时在本地临时表上使用SSIS中的全局临时表?

[英]When to use global Temp table in SSIS over Local temp table?

When to use global Temp table in SSIS over Local temp table ? 什么时候在本地临时表上使用SSIS中的全局临时表? I know the difference in terms of SQL usage but when it comes to implement in SSIS which one to prefer in which scenario ? 我知道在SQL用法方面的差异,但是在SSIS中实现时,哪种情况更适合呢?

Little theory recap for MS SQL temp tables: MS SQL临时表的理论综述很少:

  • Global temp table - you create it, fill/select, delete it. 全局临时表-创建,填充/选择,删除它。 Table remains in TempDB and is deleted when all users that are referencing the table disconnect from the instance of SQL Server. 该表保留在TempDB中,当所有引用该表的用户从SQL Server实例断开连接时,该表将被删除。 Table is accessible by other connections/sessions. 该表可通过其他连接/会话访问。
  • Local temp table - you create it and can use within your connection session. 本地临时表-您创建它并可以在您的连接会话中使用。 Table is dropped automatically when you close connection session. 关闭连接会话时,表将自动删除。

So if you need to store something just for your scope, Local tables are better, since it is deleted automatically as you close the session. 因此,如果您只需要为您的作用域存储某些内容,则本地表会更好,因为在关闭会话时会自动将其删除。 Global tables are better if you need to pass data between sessions/processes. 如果您需要在会话/进程之间传递数据,则全局表会更好。 Drawback of Global Temp tables - you have to ensure it does not exist when you create it, drop when you are done etc. 全局临时表的缺点-您必须确保它在创建时不存在,完成后删除等。

Regarding temp tables and SSIS. 关于临时表和SSIS。 SSIS usually opens a new connection for each operation with DB - Execute SQL Task. SSIS通常使用DB- 执行SQL任务为每个操作打开一个新连接。 In data flow, it opens a new connection for each component . 在数据流中,它为每个组件打开一个新连接 Therefore, local Temp table will be accessible only in one Task/Data Flow component. 因此,只能在一个“任务/数据流”组件中访问本地Temp表。 In such session pattern you have the following options: 在这种会话模式中,您可以使用以下选项:

  • Use Local temp tables within one command of Execute SQL task. 执行SQL任务的一个命令中使用本地临时表。 Another task means another connection, local temp tables are dropped. 另一个任务意味着另一个连接,将删除本地临时表。
  • Use Global temp tables and check table existence when creating, delete table afterwards etc. 使用全局临时表并在创建时检查表是否存在,然后删除表等。
  • Use Local temp tables and set RetainSameConnection=true property of related Connection Manager. 使用本地临时表并设置相关Connection Manager的RetainSameConnection=true属性。 This setting means that SSIS does not drop connection after execution of Execute SQL task. 此设置意味着SSIS在执行Execute SQL任务后不会断开连接。 In some cases SSIS still might open another connection. 在某些情况下,SSIS仍可能会打开另一个连接。 More details how to use it - see similar question . 有关如何使用它的更多详细信息,请参见类似的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM