August 31, 2016 at 11:01 pm
Comments posted to this topic are about the item Temporary tables and Table variables storage
August 31, 2016 at 11:07 pm
This was removed by the editor as SPAM
September 1, 2016 at 1:05 am
Nice and easy question.
September 1, 2016 at 1:24 am
I think the answer is wrong,
Both are stored in tempdb database.
technically table variables can just be in memory if there is only a small amount of data in them and it will page to tempdb if its gets bigger
September 1, 2016 at 4:23 am
Derek Slinn (9/1/2016)
I think the answer is wrong,Both are stored in tempdb database.
technically table variables can just be in memory if there is only a small amount of data in them and it will page to tempdb if its gets bigger
From BOL
The tempdb system database is a global resource that is available to all users connected to the instance of SQL Server and is used to hold the following:
- Temporary user objects that are explicitly created, such as: global or local temporary tables, temporary stored procedures, table variables, or cursors.
ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
September 1, 2016 at 5:17 am
A nice and simple question that will likely spark some debate. At this time, only 54% right with 256 respondents.
September 1, 2016 at 6:38 am
Wow, got that one wrong. I thought the table variables were in memory. Learned something today.
September 1, 2016 at 6:39 am
Derek Slinn (9/1/2016)
I think the answer is wrong,Both are stored in tempdb database.
technically table variables can just be in memory if there is only a small amount of data in them and it will page to tempdb if its gets bigger
That's what I thought.
September 1, 2016 at 6:58 am
Good Question, I almost tripped up on that one, attempted to over think it...
September 1, 2016 at 8:35 am
Iwas Bornready (9/1/2016)
Derek Slinn (9/1/2016)
I think the answer is wrong,Both are stored in tempdb database.
technically table variables can just be in memory if there is only a small amount of data in them and it will page to tempdb if its gets bigger
That's what I thought.
I would say it depends. The data for both starts on RAM and when they grow it's thrown to disk.
However, their definitions are stored on tempdb since the beginning. Table variables are stored as a temp table with an eight character name preceded by #.
DECLARE @Date datetime = DATEADD( ms, -10, GETDATE());
DECLARE @MyTable TABLE(someid int);
SELECT *
FROM tempdb.sys.tables
WHERE create_date BETWEEN @Date AND DATEADD( ms, 20, GETDATE());
September 1, 2016 at 9:01 am
Check Martin Smith's excellent answer at StackExchange about temporary tables vs table variables, particularly the bit about storage location: http://dba.stackexchange.com/questions/16385/whats-the-difference-between-a-temp-table-and-table-variable-in-sql-server
Cheers!
September 1, 2016 at 9:31 am
Derek Slinn (9/1/2016)
I think the answer is wrong,Both are stored in tempdb database.
technically table variables can just be in memory if there is only a small amount of data in them and it will page to tempdb if its gets bigger
Yep that's what I thought temp tables will always be created in the tempdb, table variables can flush to the tempdb if they need to but only if they need to.
September 1, 2016 at 11:34 am
Interesting discussion. Thanks!
September 1, 2016 at 12:53 pm
Mike Hays (9/1/2016)
Good Question, I almost tripped up on that one, attempted to over think it...
+1;-)
Interesting question, thanks Sergey 🙂
September 2, 2016 at 12:41 pm
SQL Server could hold everything in RAM. Yet the database objects need to be tagged as to what database they belong to. I look at it as temp tables and tables variables being borrowed from the temp database.
----------------------------------------------------
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply