[英]Where is a Table Variable created in SQL Server?
I would like to know where is the table variable created in a computer?我想知道在计算机中创建的表变量在哪里?
Let's say I declare a table variable as @emp in SQL server, can someone please help to understand where is a table variable created?假设我在 SQL Server 中将表变量声明为 @emp,有人可以帮助理解创建表变量的位置吗?
table variables are created within tempdb.表变量是在 tempdb 中创建的。 refer https://docs.microsoft.com/en-us/sql/relational-databases/databases/tempdb-database?view=sql-server-2017参考https://docs.microsoft.com/en-us/sql/relational-databases/databases/tempdb-database?view=sql-server-2017
tempdb is stored on disk, and you can check for the file location by right clicking on tempdb 存储在磁盘上,您可以通过右键单击来检查文件位置
[yourserver] > Databases > System Databases > tempdb
In the properties window, you can find the physical file location in the Files
tab.在属性窗口中,您可以在Files
选项卡中找到物理文件位置。
Table variables are alternatives of temporary tables which store a set of records.表变量是存储一组记录的临时表的替代品。
Table variable (@emp)
is created in the memory.表变量(@emp)
在内存中创建。 Whereas, a Temporary table (#temp)
is created in the t empdb database .而在 t empdb 数据库中创建了一个临时表(#temp)
。 Note:- if there is a memory pressure the pages belonging to a table variable may be pushed to tempdb .注意:- 如果存在内存压力,属于表变量的页面可能会被推送到tempdb 。
The syntax of a table variable is shown below:表变量的语法如下所示:
Declare @emp Table
(
[EmpID] [int] NULL,
[EmpName] [varchar](30) NULL,
)
Inserting a value into the table variable :在表变量中插入一个值:
Declare @emp Table
(
[EmpID] [int] NULL,
[EmpName] [varchar](30) NULL,
)
INSERT INTO @emp (EmpID, EmpName) values (1, 'Rohatash')
Select * from @emp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.