Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

Local Temporary Tables and Table Variables Expand / Collapse
Author
Message
Posted Sunday, August 31, 2008 11:17 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, October 22, 2014 7:18 AM
Points: 531, Visits: 433
Comments posted to this topic are about the item Local Temporary Tables and Table Variables


Post #561848
Posted Sunday, August 31, 2008 11:50 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:08 AM
Points: 40,415, Visits: 36,864
Very nice.

Just one small thing. You say that for data storage, temp tables are in TempDB and table variables are in memory and tempDB. I may be misunderstanding what you mean there, but temp tables are also memory resident unless it becomes necessary to write them to disk (memory pressure, too large a table)



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #561856
Posted Monday, September 1, 2008 2:43 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, November 11, 2014 9:22 AM
Points: 216, Visits: 1,372
Agree with Gail, nice article, plus I'm reading it that you're suggesting that Data Storage for Temp Table is not in memory - for which it is in-memory unless pushed out to disk.

Also, I'm taking it that, as this article is not an old one, that it covers SQL2005. If this is the case, then INSERT...EXEC is supported for Table Variables. You can test this with the following:

-- SQL2005
DECLARE @helpdb TABLE (name sysname, db_size nvarchar(13), owner sysname, dbid smallint,
created nvarchar(11), status nvarchar(600), compatibility_level tinyint)
INSERT @helpdb (name, db_size, owner, dbid, created, status, compatibility_level)
EXEC dbo.sp_helpdb
SELECT * FROM @helpdb

HTH
Post #561894
Posted Monday, September 1, 2008 11:32 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: 2 days ago @ 4:29 PM
Points: 752, Visits: 920
Awesome article that covers some of the lesser considered aspects of temporary tables and table variables. Thank you.

---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Post #562071
Posted Monday, September 1, 2008 12:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 4, 2013 4:12 AM
Points: 1, Visits: 38
The 2nd chapter about UDTs contains a mistake : the script supposed to raise an error and the workaround don't have any difference. I guess the error script should use a UDT (dbo.Name) instead of a native type (nvarchar(50)).

Thanks to all the authors and SqlserverCentral for their efforts and the useful documentation they bring us.
Post #562077
Posted Monday, September 1, 2008 2:56 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:32 PM
Points: 35,584, Visits: 32,174
Good article!

You did forget to mention one workaround for the UDT's that would allow it to work across all databases including TempDB... Define the UDT in the Master DB. Of course, most folks will argue that the Master DB is a sacred entity that should not be touched and, for the most part, I agree. :D



--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #562094
Posted Monday, September 1, 2008 4:51 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 11:54 AM
Points: 9,294, Visits: 9,492
Of course we use a startup procedure to define the UDT's in TempDB.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #562106
Posted Monday, September 1, 2008 11:16 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:47 AM
Points: 5,448, Visits: 1,401
Wonderful article..


Post #562185
Posted Monday, September 1, 2008 11:41 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:08 AM
Points: 40,415, Visits: 36,864
rbarryyoung (9/1/2008)
Of course we use a startup procedure to define the UDT's in TempDB.


Does defining them in model work as well?



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #562192
Posted Tuesday, September 2, 2008 1:31 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:56 AM
Points: 2,842, Visits: 3,876
GilaMonster (9/1/2008)
rbarryyoung (9/1/2008)
Of course we use a startup procedure to define the UDT's in TempDB.


Does defining them in model work as well?

According to this article, yes
http://www.sqlservercentral.com/articles/Advanced/3104/


Best Regards,
Chris Büttner
Post #562226
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse