删除表和截断表之间的区别? [英] Difference between drop table and truncate table?

查看:41
本文介绍了删除表和截断表之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些表格是作为报告汇总的一部分构建的.之后我根本不需要它们.有人提到要截断它们,因为它会更快.

I have some tables that I build as a part of my report rollup. I don't need them afterwards at all. Someone mentioned to truncate them as it would be faster.

推荐答案

从表中删除记录会记录每次删除并为已删除的记录执行删除触发器.截断是一个更强大的命令,它清空表而不记录每一行.SQL Server 阻止您截断带有外键引用的表,因为需要检查每一行的外键.

Deleting records from a table logs every deletion and executes delete triggers for the records deleted. Truncate is a more powerful command that empties a table without logging each row. SQL Server prevents you from truncating a table with foreign keys referencing it, because of the need to check the foreign keys on each row.

截断通常是超快的,非常适合从临时表中清除数据.它确实保留了表的结构以备将来使用.

Truncate is normally ultra-fast, ideal for cleaning out data from a temporary table. It does preserve the structure of the table for future use.

如果您确实想删除表定义以及数据,只需删除表即可.

If you actually want to remove the table definitions as well as the data, simply drop the tables.

有关详细信息,请参阅这篇 MSDN 文章

这篇关于删除表和截断表之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆