表变量创建并保存在内存或 tempdb 中?
表变量是在内存中还是在 tempdb 中创建的?同样适用于 临时表短?
Are table variables created in memory or in tempdb? Same for
short temp tables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
中的 sysobjects 表来轻松检查它,
将在 tempdb 中创建一个临时表,您可以通过查询 tempdb示例
您应该看到名称类似 #test_______000000000905 的内容,但随后带有更多下划线
如果您需要检查临时表是否存在,请参阅还有 怎么做检查 SQL Server 中是否存在临时表
表变量的结构也在 tempdb 中创建 要查看表变量,您可以执行类似的操作,但不能保证有人在您之前没有潜入创建他/她的表变量。表变量名称类似于 #7BB1235D
有关详细信息,请参阅此处:http://support.microsoft.com /kb/305977
A temp table will be created in tempdb and you can easily check for it by querying the sysobjects table in tempdb
example
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
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
For more info see here: http://support.microsoft.com/kb/305977
据我了解,至少表变量的结构始终是在 TempDB 中创建的。然后,正如SQLMenace< /a>,数据可能会也可能不会溢出。
根据这篇 Microsoft 知识库文章:
It's been my understanding that, at a minimum, the structure of a table variable is always created in TempDB. Then, as pointed out by SQLMenace, the data may or may not spill over.
Per this Microsoft Knowledge Base Article:
MS SQL 2014 中引入了特殊类型的表变量“内存优化表变量”。而且他们不使用 tempdb。
请参阅 https://msdn.microsoft.com/en-us/library/dn535766。 ASPX
In MS SQL 2014 was introduced special type of table variables "Memory-Optimized Table Variables". And they don't use tempdb.
See https://msdn.microsoft.com/en-us/library/dn535766.aspx