Online Training for Asp.net MVC Web Designing Development, MS SQL, Digital Marketing

Delete Truncate Statement in SQL Server Example


Difference between Truncate and Delete in SQL

Delete statement in SQL
Delete statement will delete data from Table, delete statement can be written with where clause.

Let's take a look at the SQL Delete example
delete from tbTeacher

//or you can write
delete from tbTeacher where teacherId = 1


sql delete statement example


Truncate statement in SQL
  • Truncate statement will delete all data from Table
  • Truncate statement reset the identity column value with seed value
  • Truncate statement cannot be written with where clause
  • if you have any FOREIGN KEY Referenced, then it will not allow to truncate the table and throw error "Cannot truncate table 'tableName' because it is being referenced by a FOREIGN KEY constraint".


Let's take a look at the SQL Truncate example
Truncate table tbTeacher

// you cannot write
Truncate table tbTeacher where teacherId = 1


sql truncate statement example
Comment
Name Email Website
Subscribe
 
Delete Truncate Statement in SQL Server Example


Difference between Delete and Truncate in SQL
Group Training