创建并保存在内存或tempdb中的表变量? [英] table variables created and held in memory or in tempdb?

查看:129
本文介绍了创建并保存在内存或tempdb中的表变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是在内存中还是在tempdb中创建表变量?相同的 简短的临时表?

Are table variables created in memory or in tempdb? Same for short temp tables?

推荐答案

将在tempdb中创建一个临时表,您可以通过查询tempdb中的sysobjects表来轻松地对其进行检查

A temp table will be created in tempdb and you can easily check for it by querying the sysobjects table in tempdb

示例

create table #test (Item char(1),  TimeSold varchar(20))

select * from tempdb.sys.sysobjects
where name like '#test%'

您应该看到类似#test _______ 000000000905的名称,但下划线更多

you should see something with a name like #test_______000000000905 but then with more underscores

如果您需要检查是否存在临时表,则另请参见

If you need to check if a temp table exists then see also How Do You Check If A Temporary Table Exists In SQL Server

Table变量的结构也在tempdb中创建.要查看表变量,您可以执行以下操作,但不能保证有人在创建他/她的表变量之前没有潜入.表变量名称将类似于#7BB1235D

The structure of Table variable is also created in tempdb To see the table variable you could do something like this but there is not guarantee that someone didn't sneak in before you when creating his/her table variable. The table variable name will be something like #7BB1235D

    declare @v table(id int) 
select top 1 * from tempdb.sys.sysobjects
where name like '#%'
and name not like '%[_]%'
order by crdate desc
select * from @v

有关更多信息,请参见此处: http://support.microsoft.com/kb/305977

For more info see here: http://support.microsoft.com/kb/305977

这篇关于创建并保存在内存或tempdb中的表变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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