有人可以解释为什么 TRUNCATE 指令需要 ALTER 特权吗?
同时 Delete 指令需要 DELETE 特权。
我知道 TRUNCATE 将页面标记为已删除,而 DELETE 将字符串标记为已删除。
因此它具有不同的事务日志用法和工作速度,但是这种知识无法理解必要特权的不同。
答案 0 :(得分:3)
很难知道为什么,但是,如果您看一下与:之间的区别:
What's the difference between TRUNCATE and DELETE in SQL
+----------------------------------------+----------------------------------------------+
| Truncate | Delete |
+----------------------------------------+----------------------------------------------+
| We can't Rollback after performing | We can Rollback after delete. |
| Truncate. (new versions allow) | | |
| Example: | Example: |
| BEGIN TRAN | BEGIN TRAN |
| TRUNCATE TABLE tranTest | DELETE FROM tranTest |
| SELECT * FROM tranTest | SELECT * FROM tranTest |
| ROLLBACK | ROLLBACK |
| SELECT * FROM tranTest | SELECT * FROM tranTest |
+----------------------------------------+----------------------------------------------+
| Truncate reset identity of table. | Delete does not reset identity of table. |
+----------------------------------------+----------------------------------------------+
| It locks the entire table. | It locks the table row. |
+----------------------------------------+----------------------------------------------+
| Its DDL(Data Definition Language) | Its DML(Data Manipulation Language) |
| command. | command. |
+----------------------------------------+----------------------------------------------+
| We can't use WHERE clause with it. | We can use WHERE to filter data to delete. |
+----------------------------------------+----------------------------------------------+
| Trigger is not fired while truncate. | Trigger is fired. |
+----------------------------------------+----------------------------------------------+
| Syntax : | Syntax : |
| 1) TRUNCATE TABLE table_name | 1) DELETE FROM table_name |
| | 2) DELETE FROM table_name WHERE |
| | example_column_id IN (1,2,3) |
+----------------------------------------+----------------------------------------------+
由于Truncate的操作方式不同,因此其权限需要有不同的要求。如果我在“为什么”委员会任职,触发器不被触发的事实对我来说将是一个很大的因素,而不能回滚的事实也将是一个很大的事实。
请记住,在定义权限时,它应该是在非常早的SQL版本上,因此更改操作所需的权限可能会被视为重大更改。
答案 1 :(得分:1)
截断将删除数据,除非它正在重置表的identity
属性。这是在处理表的结构。只是改变表。
所以我们需要ALTER
权限。
注意:未记录。出于这个原因使自己对相同的问题保持镇定。
答案 2 :(得分:0)
一个原因是您不能删除。例如,删除触发器触发器。更改不。 Alter是ametadata操作,可绕过系统中许多可能的安全措施。特别是可能进行记录或禁止或修改删除操作的触发器。