SQL服务器中临时数据的寿命 [英] Lifespan of temp data in SQL server

查看:71
本文介绍了SQL服务器中临时数据的寿命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Temp表中存储了数据,我想稍后使用它所以它仍然保存在Database.so数据保留在数据库中多长时间



我尝试过:



我已断开连接并重新连接它,仍然可以获得我之前存储的数据。

I have Stored data in Temp table,and i want to use it later on so it remains save i the Database.so how long the data remains in the database

What I have tried:

I have Disconnect the Connection and Reconnect It, still i get the Data that i stored previously.

推荐答案

对于SQL Server本地临时表 - 即用

For SQL server a local temporary table - i.e. a table created with
CREATE TABLE #TempTableName ...

。 />
所以如果你在一个存储过程中编写它,那么当程序退出时它会被清除并删除。

否则,当会话结束时它会被销毁 - 这意味着当SqlConnection已关闭。



对于全局临时表 - 即使用
创建的表

is automatically removed when the session or stored procedure ends.
So if you write it within a stored procedure, then it is cleared up and removed when the procedure exits.
Otherwise, it is destroyed when that session ends - which means when the SqlConnection is closed.

For a global temporary table - i.e. a table created with

CREATE TABLE ##TempTableName ...

略有不同。

在这种情况下,它当创建它的会话和引用它的最后一个会话结束时销毁。这是为了允许多个用户访问相同的临时数据。

it is slightly different.
In this case, it is destroyed when the session that created it and the last session referencing it ends. This is to allow multiple users access to the same temporary data.


附加参考。



快速概述:SQL Server 2005中的临时表 [ ^ ]



SQL Server中的临时表 [ ^ ]



CTE与临时表和表变量之间的区别 [ ^ ]



sql - 临时表的生命周期 - Stack Overflow [< a href =http://stackoverflow.com/questions/1834699/life-span-of-temp-tabletarget =_ blanktitle =New Window> ^ ]
Additional reference .

Quick Overview: Temporary Tables in SQL Server 2005[^]

Temporary Tables in SQL Server[^]

Difference between CTE and Temp Table and Table Variable[^]

sql - life span of temp table - Stack Overflow[^]


当创建它的连接关闭或者创建它的过程结束时,临时表将被删除。



创建和修改表格基础知识



A temp table is dropped when the connection that created it is closed or when the procedure that it was created in ends.

Creating and Modifying Table Basics

There are two types of temporary tables: local and global. They differ from each other in their names, their visibility, and their availability. Local temporary tables have a single number sign (#) as the first character of their names; they are visible only to the current connection for the user, and they are deleted when the user disconnects from the instance of SQL Server. Global temporary tables have two number signs (##) as the first characters of their names; they are visible to any user after they are created, and they are deleted when all users referencing the table disconnect from the instance of SQL Server.


这篇关于SQL服务器中临时数据的寿命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆