all groups > sql server programming > august 2007 >
You're in the

sql server programming

group:

is it faster to drop & create table or delete from instead



is it faster to drop & create table or delete from instead Coaster
8/24/2007 9:35:04 PM
sql server programming: I have a temp table, not a real temp table but a real table that I use as a
staging area for some calculations. I actually have 3 of them. During the
calculations the temp table is loaded with up to 1 million records. The
million records are deleted during iterations of the entire process. I've
been wondering if its faster to drop the temp tables and recreate them
versus deleting from.

thanks


Re: is it faster to drop & create table or delete from instead Coaster
8/24/2007 9:45:55 PM
No need to answer unless you wish to, I googled the groups and found some
simliar questions


[quoted text, click to view]

Re: is it faster to drop & create table or delete from instead Adam Machanic
8/24/2007 10:07:09 PM
Why not test both on your end and see which is better?


--

Adam Machanic
SQL Server MVP - http://sqlblog.com

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220



[quoted text, click to view]
Re: is it faster to drop & create table or delete from instead AlexS
8/25/2007 12:00:49 AM
Check truncate table
[quoted text, click to view]

Re: is it faster to drop & create table or delete from instead Coaster
8/25/2007 11:49:55 AM
I'm going to, I wasn't sure if there was a definitive answer before I did
it.


[quoted text, click to view]

Re: is it faster to drop & create table or delete from instead Adam Machanic
8/25/2007 7:21:55 PM
[quoted text, click to view]

How about dropping the table, then re-creating it with SELECT INTO
(assuming that all or most of the rows come from a single query)?


--

Adam Machanic
SQL Server MVP - http://sqlblog.com

Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
Re: is it faster to drop & create table or delete from instead Erland Sommarskog
8/25/2007 10:35:30 PM
Coaster (Coaster@Coaster.net) writes:
[quoted text, click to view]

Even better: use TRUNCATE TABLE, which performs the half of DROP TABLE
that you are interested in. And, yes, it's a lot faster than DELETE,
since TRUNCATE TABLE is minimally logged.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: is it faster to drop & create table or delete from instead Michael Burgess
8/27/2007 6:40:59 AM
[quoted text, click to view]

Agreed - it's the most efficient way to clear out a table. No
transaction logs I believe so it's quicker than delete from.
AddThis Social Bookmark Button