I have few questions which i have been asked in interview:
- Performance difference between delete and truncate?
- Delete duplicate data from a table which is not having any id column and should not use CTE.
- Why we are able to delete data using CTE?
I have few questions which i have been asked in interview:
DELETE
记录每个单独TRUNCATE
的删除,而是批量记录操作,因此速度更快。SELECT DISTINCT
数据放入临时表,TRUNCATE
然后重新插入第一个表。以下是解决您问题的一些提示:
由于 TRUNCATE 实际上并不删除数据,而是通过删除指向索引的指针来释放数据,因此它比 DELETE 快得多,当您使用 DELETE 时,所有内容都逐行存储在事务日志中,因此速度要慢得多。
http://www.codeproject.com/Tips/159881/How-to-remove-duplicate-rows-in-SQL-Server-2008-wh
http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/