Solved

TRUNCATE Table : Maintenance

Posted on 2010-09-17
11
206 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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:
Scott Pletcher 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:Scott Pletcher
Scott Pletcher 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

777 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