即使发生错误,如何强制创建存储过程?

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.

这篇关于即使发生错误,如何强制创建存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)