DROP...CREATE vs ALTER(删除...创建与更改)
问题描述
在创建存储过程、视图、函数等时,对对象执行 DROP...CREATE 还是 ALTER 更好?
When it comes to creating stored procedures, views, functions, etc., is it better to do a DROP...CREATE or an ALTER on the object?
我已经看到许多标准"文档声明要执行 DROP...CREATE,但我已经看到了许多支持 ALTER 方法的评论和论点.
I've seen numerous "standards" documents stating to do a DROP...CREATE, but I've seen numerous comments and arguments advocating for the ALTER method.
ALTER 方法保留了安全性,而我听说 DROP...CREATE 方法会在第一次执行时强制对整个 SP 进行重新编译,而不仅仅是语句级别的重新编译.
The ALTER method preserves security, while I've heard that the DROP...CREATE method forces a recompile on the entire SP the first time it's executed instead of just a a statement level recompile.
有人可以告诉我使用一种比另一种有其他优点/缺点吗?
Can someone please tell me if there are other advantages / disadvantages to using one over the other?
推荐答案
ALTER 还将强制重新编译整个过程.语句级重新编译适用于过程内部的语句,例如.单个 SELECT,由于基础表更改而重新编译,无需对过程进行任何更改.甚至不可能选择性地重新编译 ALTER 过程中的某些语句,以便了解 在 ALTER 过程之后 SQL 文本中发生了什么变化,服务器必须……编译它.
ALTER will also force a recompile of the entire procedure. Statement level recompile applies to statements inside procedures, eg. a single SELECT, that are recompiled because the underlying tables changes, w/o any change to the procedure. It wouldn't even be possible to selectively recompile just certain statements on ALTER procedure, in order to understand what changed in the SQL text after an ALTER procedure the server would have to ... compile it.
对于所有对象,ALTER 总是更好,因为它保留了所有安全性、所有扩展属性、所有依赖项和所有约束.
For all objects ALTER is always better because it preserves all security, all extended properties, all dependencies and all constraints.
这篇关于删除...创建与更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除...创建与更改


基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01