How to forcibly create stored procedure even if some error occurs?(即使发生错误,如何强制创建存储过程?)
问题描述
当我执行数据库脚本时,我在存储过程中出错,然后它无法创建有错误的存储过程.即使存储过程发生错误,我也想强行创建存储过程.
When I execute database script, I got errors in stored procedure then it couldn't create that stored procedure that have errors. I want to forcibly create stored procedure even if some error occur in stored procedure.
如果在 create procedure 语句中发生错误,则不会创建存储过程.我想要的是无论如何都会创建存储过程,无论是否发生错误.
If some error occurred in the create procedure statement it won't create stored procedure. What I want is that stored procedure will be created anyway, whether an error occurred or not.
实际上我们在 SQL Server 2000 中有数据库,我在 SQL Server 2005 中附加了它,然后将兼容级别更改为 90.最后我想执行该脚本,但我也希望如果发生某些错误,它将忽略错误并创建对象.
Actually we have database in SQL Server 2000, I attached it in SQL Server 2005 and then change the compatibility level to 90. And finally I want to execute the script but I also want that if some error occurred then it will ignore error and create the objects.
推荐答案
您可以通过以不能失败的方式创建存储过程来强制创建它.看这个例子:
You can force the creation of a stored procedure by creating it in a can't-fail way. See this example:
if object_id('sp_name') is null
exec sp_executesql N'create procedure dbo.sp_name as select 1'
go
alter procedure db.sp_name
as
...
go
现在如果更改失败,无论如何都会有一个存储过程.
Now if the alter fails, there will be a stored procedure anyway.
这篇关于即使发生错误,如何强制创建存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:即使发生错误,如何强制创建存储过程?
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
