C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
5
Reply
Difference temdb table and table variable?
M SK
11y
2.1k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
#temp table = data stored in tempdb and scope is limited to sp. ##temp table =globle temp table stored in tempdb scope is in all connections. @temp table variable = stored in memory scope upto sp executes @temp table is good option.
Vishal Jadav
9y
0
Tempdb store all your temp or global table, cursor, table variables and temp sp. Table variable is just like temporary table but its performance is better in terms of compilation and use of resource than temp table.
Madhuri Mishra
10y
0
The first difference is that transaction logs are not recorded for the table variables. Hence, they are out of scope of the transaction mechanismAfter declaring our temporary table #T and our table-variable @T, we assign each one with the same "old value" string. Then, we begin a transaction that updates their contents. At this point, both will now contain the same "new value" string. But when we rollback the transaction, as you can see, the table-variable @T retained its value instead of reverting back to the "old value" string. This happened because, even though the table-variable was updated within the transaction, it is not a part of the transaction itself.The second major difference is that any procedure with a temporary table cannot be pre-compiled, while an execution plan of procedures with table variables can be statically compiled in advance. Pre-compiling a script gives a major advantage to its speed of execution. This advantage can be dramatic for long procedures, where recompilation can be too pricy.Finally, table variables exist only in the same scope as variables. Contrary to the temporary tables, they are not visible in inner stored procedures and in exec(string) statements. Also, they cannot be used in an insert/exec statement.
Kml Surani
10y
0
There is good article on: 16 main differences between Temporary Table and Table Variable in Sql Server
http://www.webcodeexpert.com/2015/02/difference-between-temporary-table-and.html
Lalit Raghuvanshi
10y
0
http://blog.sqlauthority.com/2009/12/15/sql-server-difference-temptable-and-table-variable-temptable-in-memory-a-myth/
Virendra Gaur
11y
0
Message