Loading...

Today, We are going to discuss about difference between Delete and Truncate SQL Statement. In this post we will find key difference between Delete and Truncate. 

Delete 
  1. Delete statement is used to remove single or multiple rows from SQL Table.
  2. We can use where clause to remove single or multiple rows of Table.
  3. If we used Identity in columns (auto increments / decrements column value)  and we delete last row then next row will automatically start next values of identity of last row.
We are taking an example of below table. In this table ID column set Identity.
 

ID

Name

Sal

1

Ram

25000

2

Mohan

20000

3

Suresh

30000

4

Ravi

35000

5

Kishan

20000

6

Rakesh

25000


Now, We will remove information of Rakeshfrom table. And alter then add a new record Vijay then see what happen in ID column.
Delete from Tbl1 where ID=6

Adding new rows in table
Insert into Tbl1 (Name,Sal) values ('Vijay', 24000)

ID

Name

Sal

1

Ram

25000

2

Mohan

20000

3

Suresh

30000

4

Ravi

35000

5

Kishan

20000

7

Vijay

24000


Here, we can see information of Rakesh has been removed and New record of Vijay with next value in ID like 7.