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.
这篇关于即使发生错误,如何强制创建存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:即使发生错误,如何强制创建存储过程?


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01