Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Using Truncate table in Procedure using Sql Server 2005.

Author: Zunnair

In this Article I will explain the best use of truncate table command. Why we should use truncate on the place of delete in Some Circumstances.

We usually use delete command in our sql scripts but we don’t know why we do not use truncate command.

Basically when we use the delete the table we actually deleting records from database’s table and maintaining the logs of deleting records. Like when we delete some thing from our computer and it goes to recycle bin.

But when we use truncate table command then we tell sql server that we don’t need logs of deleted records. Like when we delete some thing from our computer by Shift Delete.

 

So, we should use truncate and delete according to the circumstances because we should know that truncate command much faster than delete.

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[USP_TEST] AS

Truncate Table tblTest

INSERT INTO [tblTest]

(

[TestCol1],

[TestCol2],

[TestCol3],

[TestCol4],

[TestCol5],

[TestCol6]

)

Select

[TestCol1],

[TestCol2],

[TestCol3],

[TestCol4],

[TestCol5],

[TestCol6]

from tblTest2

where TestCol1 = ‘Test’

 

I hope this article will help you allot in understanding the difference between delete and truncate records.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Using "sys.objects" in Sql Server 2008 using PL-SQL

Disclaimer - Privacy
© 2002-2017 DevASP.net