Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating temp tables

Author  Topic 

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-12-09 : 14:23:58
Hi all, just a couple quick questions about creating temp tables: do you do the whole CREATE TABLE #HelpImTrappedInTheInterwebs thing or just SELECT...INTO #NoReallyHelpMeHesAMonster and be done with it? If you CREATE, do you also set a primary key?

I guess my question is really about common/best practices when creating temp tables.

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-09 : 14:38:17
It depends on what I need to do. Adding primary keys and other indexes also depends on what I need to do. If I use SELECT/INTO to create it, then I still may add primary key and/or indexes.

The answer is "it depends".



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Aleph_0
Yak Posting Veteran

79 Posts

Posted - 2011-12-09 : 15:13:44
quote:
Originally posted by tkizer

It depends on what I need to do. Adding primary keys and other indexes also depends on what I need to do. If I use SELECT/INTO to create it, then I still may add primary key and/or indexes.

The answer is "it depends".



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Oh good - I don't feel so bad now. I've only been using CREATE when the table is large and adding a primary key speeds things up. What other reasons would make you use CREATE?

Thanks for your input!
Go to Top of Page
   

- Advertisement -