Solved

TRUNCATE Table : Maintenance

Posted on 2010-09-17
11
205 Views
Last Modified: 2013-12-01
Hi,
  After truncating table what maintenance job should be done? I might have to truncate tables several times.

Thanks.
0
Comment
Question by:arunbhatt
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 166 total points
ID: 33701846
you should rebuild the indexes, to ensure statistics are updated (otherwise sql might "think" the table is still "full" in regards to evaluating a explain plan ...)
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33701930
you need to rebuild index.
Why not you drop table and recreate it, instead of truncating it.
0
 

Author Comment

by:arunbhatt
ID: 33702220
Hi,
   This will be temorary processing table. What is the advantage of dropping over truncate?

Thanks.
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33702324
temorary processing table means? #temp table?

if yes, then you dont need to rebuide indexes etc.., only consider to shrink tempdb time by time.
0
 

Author Comment

by:arunbhatt
ID: 33702357
Hi,
  The temporary table would be actual table without # in front of table name. What should be the approach?


Thanks.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33702413
1. Remove its all ref., like foreign keys etc.. (remove related data from other tables)
2. Rebuild Indexs

0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 334 total points
ID: 33702709
TRUNCATE is the best approach if available.

All indexes will be automatically emptied by the TRUNCATE.

I thought statistics were too, but if you want to be sure, just issue this command after the TRUNCATE:

UPDATE STATISTICS tablename

So, in summary:

TRUNCATE TABLE tablename
UPDATE STATISTICS tablename
0
 

Author Comment

by:arunbhatt
ID: 33707631
Hi,
  Why TRUNCATE is better than DROP command?

Thanks.
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 334 total points
ID: 33716892
TRUNCATE will be faster, since the data structure does not have to be removed.

DROP will lose all objects associated with the table, including but not limited to:
indexes
permissions
foreign keys
defaults
check constraints
etc.

ALL of that is deleted if you DROP the table.

Whereas, if you TRUNCATE the table, only the rows are deleted.
0
 
LVL 22

Expert Comment

by:Steve Wales
ID: 39687907
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now