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?
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?
table variables are created within tempdb. refer https://learn.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
[yourserver] > Databases > System Databases > tempdb
In the properties window, you can find the physical file location in the Files
tab.
Table variables are alternatives of temporary tables which store a set of records.
Table variable (@emp)
is created in the memory. Whereas, a Temporary table (#temp)
is created in the tempdb database.
Note:- if there is a memory pressure the pages belonging to a table variable may be pushed to 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