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’