top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to use Truncate table in Procedure using Sql Server 2005?

0 votes
386 views
How to use Truncate table in Procedure using Sql Server 2005?
posted Mar 17, 2016 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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’
answer Mar 17, 2016 by Shivaranjini
...